php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26441 Strange behavior when __set() return a member variable
Submitted: 2003-11-28 01:13 UTC Modified: 2004-04-09 10:43 UTC
From: chernyshevsky at hotmail dot com Assigned: andi (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-03-30 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: chernyshevsky at hotmail dot com
New email:
PHP Version: OS:

 

 [2003-11-28 01:13 UTC] chernyshevsky at hotmail dot com
Description:
------------
When __set() returns an element of a member array, it seems to corrupt the array. Works as expected when "return" is removed. 

Reproduce code:
---------------
class Test {
	var $values;
	
	function __construct() {
		$this->values = array();
	}

	function __set($name, $value) {
		return $this->values[$name] = $value;
	}

	function __get($name) {
		return $this->values[$name];
	}
};

$a = new Test();
$a->greeting = "Hello";
echo $a->greeting;

Expected result:
----------------
Hello

Actual result:
--------------
1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-31 23:12 UTC] chernyshevsky at hotmail dot com
I think it was marked bogus because you don't actually need to return from __set(). The engine will call __get() when you have something like $a = $object->prop = "Hello".
 [2004-04-01 01:02 UTC] amt@php.net
Okay, but it still shouldn't act screwy when you do 
return that value. It should just ignore the return 
value of __set().
 [2004-04-07 11:19 UTC] sniper@php.net
Andi, you decide if this is docu prob or real bug.. :)

 [2004-04-09 10:43 UTC] andi@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 15:01:30 2024 UTC