php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31109 cannot pass result of __get by reference
Submitted: 2004-12-16 06:27 UTC Modified: 2005-01-10 23:34 UTC
From: rampant at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.0.1 OS: WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rampant at gmail dot com
New email:
PHP Version: OS:

 

 [2004-12-16 06:27 UTC] rampant at gmail dot com
Description:
------------
From outside a class, accessing a variable via a __get is identical to accessing one via a public member:

$publ->varr
vs.
$gets->varr

When trying to pass by reference, I would expect the corresponding __set to be called when the value originaly came from a __get. Instead, there is a Fatal error.

Reproduce code:
---------------
class PublicVar {
	public $varr;
}

class GetSetter {
	
	protected $data = array();
	
	function __get($key) {
		return $this->data[$key];
	}
	
	function __set($key, $value) {
		$this->data[$key] = $value;
	}
}

function set_by_ref(&$variable) {
	$variable = 'has been set, ';
}

$publ = new PublicVar();
set_by_ref($publ->varr);
echo $publ->varr;

$gets = new GetSetter();
set_by_ref($gets->varr);
echo $gets->varr;

Expected result:
----------------
has been set, has been set, 

Actual result:
--------------
has been set
Fatal error: Cannot access undefined property for object with overloaded property access in C:\eclipse\workspace\tmote\tmp_byref.php on line 27

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-16 12:46 UTC] dennis at inmarket dot lviv dot ua
This is bug #28444
 [2005-01-10 23:34 UTC] tony2001@php.net
Duplicate of #28444, as was pointed by Dennis.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Mar 12 11:01:32 2025 UTC