|  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: -
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
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

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Jun 18 08:01:24 2021 UTC