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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 22:01:26 2024 UTC