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

From: Date: Fri, 29 Nov 2013 10:04:34 +0000
Subject: Bug #66200 [NEW]: the new operator DON'T returns a reference automatically
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183005@lists.php.net to get a copy of this message
From: erwan dot oger35 at gmail dot com Operating system: PHP version: 5.4.22 Package: Class/Object related Bug Type: Bug Bug description:the new operator DON'T returns a reference automatically 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 bug report at https://bugs.php.net/bug.php?id=66200&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66200&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66200&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66200&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66200&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66200&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66200&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66200&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66200&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66200&r=support Expected behavior: https://bugs.php.net/fix.php?id=66200&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66200&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66200&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66200&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66200&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66200&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66200&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66200&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66200&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66200&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66200&r=mysqlcfg

« previous php.bugs (#183005) next »