php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #77808 Undocumented behaviour on assign by reference with magic getters
Submitted: 2019-03-27 14:19 UTC Modified: -
From: christian dot mohr at insitu dot de Assigned:
Status: Open Package: Documentation problem
PHP Version: 7.1.27 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-03-27 14:19 UTC] christian dot mohr at insitu dot de
Description:
------------
Assigning by reference to an non-existing property of an object works as expected (like any assign-by-value). But if the object contains a magic __get() method the behaviour is undocumented. Why is the magic getter invoked? Why does the assignment fail? Is there any way to get the expected behaviour with the magic getter in place?


Removing either the magic getter OR the assign-by-reference "&" (assign-by-value instead) produces the expected result.

Test script:
---------------
Class CLS
{
	public function &__get($key) {
		echo "__get " . $key . PHP_EOL;
		return $this->$key;
	}
}

$magicTest = new CLS();

$test = "test";
$magicTest->v = & $test;
echo ($magicTest->v ?? "null") . PHP_EOL;

Expected result:
----------------
test

Actual result:
--------------
__get v
null

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 02:01:25 2019 UTC