Doc #77808 [NEW]: Undocumented behaviour on assign by reference with magic getters

From: Date: Wed, 27 Mar 2019 14:19:52 +0000
Subject: Doc #77808 [NEW]: Undocumented behaviour on assign by reference with magic getters
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16525@lists.php.net to get a copy of this message
From:             christian dot mohr at insitu dot de
Operating system: 
PHP version:      7.1.27
Package:          Documentation problem
Bug Type:         Documentation Problem
Bug description:Undocumented behaviour on assign by reference with magic getters

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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=77808&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=77808&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=77808&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=77808&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=77808&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=77808&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=77808&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=77808&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=77808&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=77808&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=77808&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=77808&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=77808&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=77808&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77808&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=77808&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=77808&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=77808&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77808&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=77808&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=77808&r=mysqlcfg



Thread (2 messages)

« previous php.doc.bugs (#16525) next »