References challenge with PHP4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've the following code:

 1 <?php
 2
 3 class B {
 4   function B(&$a) {
 5     $this->a = &$a;
 6   }
 7
 8   function run() {
 9     print "{$this->a->msg}\n";
 10   }
 11 }
 12
 13 class A {
 14   function A() {
 15     $this->b = new B(&$this);
 16   }
 17
 18   function &getInstance() {
 19     static $inst;
 20     if(!isset($inst)) $inst = new A();
 21     return $inst;
 22   }
 23
 24   function run() {
 25     $this->b->run();
 26   }
 27 }
 28
 29 $a = &A::getInstance();
 30 $a->msg = "Hello world !";
 31
 32 // Some tasks, flow control, scope changes, ...
 33
 34 $a = &A::getInstance();
 35 print "{$a->msg}\n"; // This should print "Hello world !"
 36 $a->run(); // This should print "Hello world !"
 37
 38 ?>

My problem is that I don't know what I need to do in order to print
the same value in lines 35 and 36. Line 35 prints "Hello world !", but
in the 36 nothing appears.  What I'm doing wrong ?

Thanks for all !

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux