|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53770 __set isn't called on ref assignment
Submitted: 2011-01-17 22:50 UTC Modified: 2021-07-28 15:48 UTC
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: stormingphoenix at yahoo dot com Assigned:
Status: Verified Package: Class/Object related
PHP Version: 5.3.5 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
38 - 26 = ?
Subscribe to this entry?

 [2011-01-17 22:50 UTC] stormingphoenix at yahoo dot com
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) {
	class bar {
		var $that = 'that';
	$that = 'that';
	$foo = new foo();
	$foo->Property =& $that;
	$bar = new bar();
	$foo->Property =& $bar;

Expected result:
string(4) "here" 
undefined variable: $bar

Actual result:
string(4) "that"
object(bar)#7 (1) { ["that"]=> string(4) "that" } 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-28 15:48 UTC]
-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]
> 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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 22 12:01:29 2024 UTC