Bug #66200 [Opn]: the new operator DON'T returns a reference automatically

From: Date: Fri, 29 Nov 2013 10:25:31 +0000
Subject: Bug #66200 [Opn]: the new operator DON'T returns a reference automatically
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183006@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66200&edit=1 ID: 66200 User updated by: erwan dot oger35 at gmail dot com Reported by: erwan dot oger35 at gmail dot com Summary: the new operator DON'T returns a reference automatically Status: Open Type: Bug Package: Class/Object related PHP Version: 5.4.22 Block user comment: N Private report: N New Comment: Note that even you change : "$a2 = &$a;" by : "ObjHandler::link($a);" it returns the same result !! Previous Comments: ------------------------------------------------------------------------ [2013-11-29 10:04:34] erwan dot oger35 at gmail dot com Description: ------------ --- From manual page: http://www.php.net/language.operators.assignment --- "As of PHP 5, the new operator returns a reference automatically, so assigning the result of new by reference results in an E_DEPRECATED message in PHP 5.3 and later, and an E_STRICT message in earlier versions." Test script: --------------- <?php class A { private $name; private $counter; public function __construct ( $name ) { $this->name = $name; $this->counter = 0; } public function __destruct () { echo __METHOD__. ' : '. $this->name . ' ('.(++$this->counter).')<br/><br/>'.PHP_EOL.PHP_EOL; } } class B { private $name; private $counter; public function __construct ( $name ) { $this->name = $name; $this->counter = 0; ObjHandler::link($this); } public function __destruct () { echo __METHOD__. ' : '. $this->name . ' ('.(++$this->counter).')<br/><br/>'.PHP_EOL.PHP_EOL; } } class ObjHandler { private static $objLinked = array(); public static function link ( &$obj ) { self::$objLinked[] = &$obj; } } $a = new A('a'); $a2 = &$a; $a = null; $b = new B('b'); $b = null; Expected result: ---------------- A::__destruct : a (1) B::__destruct : b (1) FIN Actual result: -------------- A::__destruct : a (1) FIN B::__destruct : b (1) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66200&edit=1

« previous php.bugs (#183006) next »