php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71477 Inconsist behavior during assign-by-reference in __get()
Submitted: 2016-01-28 10:10 UTC Modified: 2016-03-22 09:10 UTC
From: arepo at nologin dot ru Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: arepo at nologin dot ru
New email:
PHP Version: OS:

 

 [2016-01-28 10:10 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-28 10:22 UTC] requinix@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2016-03-22 09:10 UTC] arepo at nologin dot ru
-Status: Open +Status: Closed
 [2016-03-22 09:10 UTC] arepo at nologin dot ru
Resolved in 7.0.4
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 21:01:33 2024 UTC