|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-07-28 15:48 UTC] cmb@php.net
-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
[2021-07-28 15:48 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 01:00:01 2025 UTC |
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" }