Re: Getting new object by ref.

From: Date: Thu, 21 Dec 2000 22:24:57 +0000
Subject: Re: Getting new object by ref.
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-42084@lists.php.net to get a copy of this message
It does work, only not with the semantics you expected, but with PHP's assign-reference semantics. $a = &$b; // $a and $b are references to the same value
$a = &$c;       // $a is broken away from $b, and now, $a and $c are references to the same
                // variable - $b is standalone
The same thing happens here. As you know, 'global $foo' creates a local variable, $foo, which is a reference to the $foo variable in the global scope. If you assign-reference to the local $foo, the reference to the global $foo will be broken. Zeev At 00:05 22/12/2000, Frank M. Kromann wrote:
Hi All, $object = &new myTest(); does not work when used inside a function. Changing it to $object = new myTest(); makes the function work. - Frank Sample code: class myTest {
        var $data;
        function myTest() {
                $this->data = "Test";
        }
        function GetData() {
                return $this->data;
        }
} $object = null; function init() {
        global $object;
        $object = &new myTest();
} function write() {
        global $object;
        print($object->GetData() . "\n");
} /* main */ init(); write(); -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- Zeev Suraski <zeev@zend.com> CTO & co-founder, Zend Technologies Ltd. http://www.zend.com/

« previous php.dev (#42084) next »