Req->Doc #53770 [Opn->Ver]: __set isn't called on ref assignment
| From: | cmb@php.net | Date: | Wed, 28 Jul 2021 15:48:19 +0000 |
| Subject: | Req->Doc #53770 [Opn->Ver]: __set isn't called on ref assignment | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-19000@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53770&edit=1
ID: 53770
Updated by: cmb@php.net
Reported by: stormingphoenix at yahoo dot com
-Summary: __set Doesn't Allow Pass By Reference (Even On
Objects) And Isn't Called On Ref
+Summary: __set isn't called on ref assignment
-Status: Open
+Status: Verified
-Type: Feature/Change Request
+Type: Documentation Problem
Package: Class/Object related
Operating System: All
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
> Not a major issue, but at the least the __set not being called
> may need to be fixed.
Even if we wanted, we couldn't fix this for BC reasons. And I
wouldn't even want to have that fixed. We should document the
behavior, though.
Previous Comments:
------------------------------------------------------------------------
[2011-01-17 22:50:01] stormingphoenix at yahoo dot com
Description:
------------
When using __set($strProp, &$strValue), you are given the error:
Method foo::__set() cannot take arguments by reference
If, you use $obj->property =& $that it will not call __set at all, but rather auto-create
'property';
Not a major issue, but at the least the __set not being called may need to be fixed.
Test script:
---------------
class foo {
private $var = NULL;
function __set($strProp, $strValue) {
var_dump('here');
unset($strValue);
}
}
class bar {
var $that = 'that';
}
error_reporting(E_STRICT);
$that = 'that';
$foo = new foo();
$foo->Property =& $that;
var_dump($foo->Property);
var_dump($that);
$bar = new bar();
$foo->Property =& $bar;
var_dump($bar);
Expected result:
----------------
string(4) "here"
undefined variable: $bar
Actual result:
--------------
string(4) "that"
object(bar)#7 (1) { ["that"]=> string(4) "that" }
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53770&edit=1