You are here: function using global object in PHP5 failes « PHP Programming Language « IT news, forums, messages
function using global object in PHP5 failes

Posted by Arne Claus on 06/27/05 15:47

Hi.
I've got a strange problem here with PHP5 (5.0.4). I've got file A,
defining a class A and a file B, which sets up an Object of A (aObj) in
the global scope like this.

----- A.php ----
class A {
//...
}

----- B.php ----
require_once "A.php";
$aObj = new A();

Ok - that's the setup so far. Now I include B.php in a file C.php,
which lets me (correctly) acces aObj in the global scope, but not in a
function defined there. And I _do_ use global:

----- C.php -----
require_once "B.php";

echo $aObj->some_member; // works

function test() {
global $aObj;
echo $aObj->some_member; // does not work "Notice: Trying to get
property of non-object"
}

Did I miss something here or did the behaviour of the global operator
change in PHP5?
Arne

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация