php.net |  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
Votes:3
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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: stormingphoenix at yahoo dot com
New email:
PHP Version: OS:

 

 [2011-01-17 22:50 UTC] 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" } 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
> 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: Tue Mar 19 05:01:29 2024 UTC