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

From: Date: Tue, 22 Mar 2016 09:10:21 +0000
Subject: Bug #71477 [Opn->Csd]: Inconsist behavior during assign-by-reference in __get()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200022@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71477&edit=1

 ID:                 71477
 User updated by:    arepo at nologin dot ru
 Reported by:        arepo at nologin dot ru
 Summary:            Inconsist behavior during assign-by-reference in
                     __get()
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Scripting Engine problem
 PHP Version:        7.0.2
 Block user comment: N
 Private report:     N

 New Comment:

Resolved in 7.0.4


Previous Comments:
------------------------------------------------------------------------
[2016-01-28 10:10:43] arepo at nologin dot ru

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 this bug report at https://bugs.php.net/bug.php?id=71477&edit=1


Thread (1 message)

  • arepo at nologin dot ru
  • Unknown Message
    • arepo at nologin dot ru
« previous php.bugs (#200022) next »