Classes, global objects, and pointers

From: Date: Wed, 12 Feb 2003 03:04:46 +0000
Subject: Classes, global objects, and pointers
Groups: php.general 
Request: Send a blank email to php-general+get-135261@lists.php.net to get a copy of this message
In this example which parallels a problem I am having in my real life script. I would like to have a global object, in this case $tester. I would then like to be able to store local references to this global object right inside the class. These are assigned byref in the classes constructor. This script should, by my understanding work, only it craps out in test2's constructor: "$o = &$tester;". Any help would be greatly appreciated. (Please cc me on your replies) John Hughes <?php class test { var $a; function test() { $this->a = 10; } function doit() { $this->a = 20; } } global $tester; $tester = new test(); class test2 { var $o; function test2() { $o = &$tester; } function mod() { $o->doit(); } } echo $tester->a . "\n"; // Should be 10 $newtest = new test2(); $newtest->mod(); echo $tester->a . "\n"; // Should be 20 ?>

« previous php.general (#135261) next »