Re: Classes, global objects, and pointers

From: Date: Wed, 12 Feb 2003 12:41:15 +0000
Subject: Re: Classes, global objects, and pointers
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-135300@lists.php.net to get a copy of this message
John Hughes wrote:
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; } } you don't need to make it global here in global scope
global $tester; $tester = new test(); class test2 { var $o; function test2() { but here
$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 (#135300) next »