Bug #71477 [NEW]: Inconsist behavior during assign-by-reference in __get()

From: Date: Thu, 28 Jan 2016 10:10:45 +0000
Subject: Bug #71477 [NEW]: Inconsist behavior during assign-by-reference in __get()
Groups: php.standards 
Request: Send a blank email to standards-+get-1018@lists.php.net to get a copy of this message
From: arepo at nologin dot ru Operating system: PHP version: 7.0.2 Package: PHP Language Specification Bug Type: Bug Bug description:Inconsist behavior during assign-by-reference in __get() Description: ------------ In PHP 7+ assign-by-ref creates a property BEFORE calling $this->getProp($name). This behavior is described in the documentations only for arrays. You can see result in https://3v4l.org/PBZRS Test script: --------------- <?php class MagicByRef { private $prop = 'hello'; private function &getProp($name) { printf( "%s: %s is %s\n", __METHOD__, $name, property_exists($this, $name) ? 'exists' : 'not exists' ); return $this->prop; } public function __set($name, $value) { echo __METHOD__ , "($name, $value)\n"; } public function &__get($name) { echo __METHOD__ , "($name)\n"; $this->$name = &$this->getProp($name); return $this->$name; } } echo 'Assignment by reference: $this->$name = &$this->getProp($name)', ":\n"; $m = new MagicByRef; $m->hello; Expected result: ---------------- Assignment by reference: $this->$name = &$this->getProp($name): MagicByRef::__get(hello) MagicByRef::getProp: hello is not exists Actual result: -------------- Assignment by reference: $this->$name = &$this->getProp($name): MagicByRef::__get(hello) MagicByRef::getProp: hello is exists -- Edit bug report at https://bugs.php.net/bug.php?id=71477&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71477&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71477&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71477&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71477&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71477&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71477&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71477&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71477&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71477&r=support Expected behavior: https://bugs.php.net/fix.php?id=71477&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71477&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71477&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71477&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71477&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71477&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71477&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71477&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71477&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71477&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71477&r=mysqlcfg

« previous php.standards (#1018) next »