php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53770 __set Doesn't Allow Pass By Reference (Even On Objects) And Isn't Called On Ref
Submitted: 2011-01-17 22:50 UTC Modified: -
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: Open Package: Class/Object related
PHP Version: 5.3.5 OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Feb 15 18:01:25 2019 UTC