|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-06-14 11:57 UTC] sjon@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: sjon
[2019-06-14 11:57 UTC] sjon@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Jan 07 05:00:01 2026 UTC |
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