php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29175 __get and __set are not called when property explicitly defined public or var
Submitted: 2004-07-15 03:56 UTC Modified: 2004-07-15 17:51 UTC
From: jbeall at heraldic dot us Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0 OS: Linux
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: jbeall at heraldic dot us
New email:
PHP Version: OS:

 

 [2004-07-15 03:56 UTC] jbeall at heraldic dot us
Description:
------------
If you define a property as public, and then also define the __get() and __set() functions within the same class, those functions are not called.

Reproduce code:
---------------
class Sub
{
	public $someProp;
	function __get($prop)
	{
		echo "Property $prop called\n";
	}

	function __set($prop, $val)
	{
		echo "Property $prop set to $val\n";
	}
}


$foo = new Sub();

$foo->someProp = 10;
echo $foo->someProp;

Expected result:
----------------
Property someProp set to 10
Property someProp called

Actual result:
--------------
10

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-15 04:20 UTC] amt@php.net
This is the intended behavior. __get() and __set() are 
only triggered when a property *does not* exist.
 [2004-07-15 14:33 UTC] jbeall at heraldic dot us
Interesting.  The documentation suggests otherwise, both here: http://us2.php.net/manual/en/migration5.oop.php#migration5.oop.overload and here: http://us4.php.net/overload

It would probably be a good idea to update the docs so they make it clear what the intended behavior is.
 [2004-07-15 17:51 UTC] amt@php.net
I updated the manual's XML source to mention this in the PHP 5 Migration section.

The overload section, as already marked in the manual, is for PHP 4 only and not PHP 5.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 22:01:31 2024 UTC