php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38176 overloading is ignored when using reference
Submitted: 2006-07-21 15:04 UTC Modified: 2006-07-24 07:37 UTC
From: pedro dot leite dot rocha at gmail dot com Assigned: dmitry (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.4 OS: Linux 2.6.15-26-686
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 !
Your email address:
MUST BE VALID
Solve the problem:
26 + 32 = ?
Subscribe to this entry?

 
 [2006-07-21 15:04 UTC] pedro dot leite dot rocha at gmail dot com
Description:
------------
When using overloading with the special function __set, and passing the value by reference, the overload is ignored, and a new attribute for the class object is created.

I'm not sure if this is a bug, but I couldn't find anything like it in the documentation, or in the bug list. Appreciate the help.
[]'s

Reproduce code:
---------------
class A {
	private $v;
	function __construct() {
		echo "constructing...\n";
	}
	function __set($key, $value) {
		echo "setting ".$key."\n";
		$this->v[$key] = $value;
	}
}

$foo = "bar";
$a = new A;
echo "without reference:\n";
$a->user = $foo;
echo "with reference:\n";
$a->user =& $foo;
var_dump($a);


Expected result:
----------------
constructing...
without reference:
setting user
with reference:
object(A)#1 (2) {
  ["v:private"]=>
  array(1) {
    ["user"]=>
    &string(3) "bar"
  }
}


Actual result:
--------------
constructing...
without reference:
setting user
with reference:
object(A)#1 (2) {
  ["v:private"]=>
  array(1) {
    ["user"]=>
    string(3) "bar"
  }
  ["user"]=>
  &string(3) "bar"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-24 07:37 UTC] dmitry@php.net
This is not a bug (may be a logical inconsistency).

Method __set() is used for modification values of overloaded properties and it cannot be used to assigment by reference.

Implement method __get and you will get "Fatal error: Cannot assign by reference to overloaded object ...".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 09:01:29 2024 UTC