php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29070 __get/__set should allow recursive calls
Submitted: 2004-07-09 06:57 UTC Modified: 2006-03-01 08:30 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:2 (66.7%)
From: csmoak at andrew dot cmu dot edu Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.0.0RC3 OS: All
Private report: No CVE-ID: None
 [2004-07-09 06:57 UTC] csmoak at andrew dot cmu dot edu
Description:
------------
__get() and __set() are currently blocked from being implicitly called for a particular instance of an object when they are currently executing. However, this can cause code to behave differently if it is called from within __get()/__set() or if it is called without __get()/__set().

The following example uses good OOP methodology that tries to make use of __get() and __set(), but is hindered by it, instead.

The problem lies in the use of the in_get and in_set member variables in the zend_object strcut to provide a blanket block to calling __get or __set recursively (when called implicitly). A possible solution would be to only prevent code directly in the __get() and __set() method bodies from implicitly calling __get() or __set(), but allowing it in any called code.

Reproduce code:
---------------
http://www.andrew.cmu.edu/user/csmoak/getset.phps

Expected result:
----------------
correct behavior (without making use of __get/__set):<br>
before set : default<br>
after set  : propertyValue<br>
PropertyAccessClass Object
(
    [property:private] => propertyValue
    [defaultProperty:private] => default
    [changed:private] => 1
)
<br><br>

incorrect behavior (making use of __get/__set):<br>
before set : default<br>
after set  : propertyValue<br>
PropertyAccessClass Object
(
    [property:private] => propertyValue
    [defaultProperty:private] => default
    [changed:private] => 1
)

Actual result:
--------------
correct behavior (without making use of __get/__set):<br>
before set : default<br>
after set  : propertyValue<br>
PropertyAccessClass Object
(
    [property:private] => propertyValue
    [defaultProperty:private] => default
    [changed:private] => 1
)
<br><br>

incorrect behavior (making use of __get/__set):<br>
<br />
<b>Notice</b>:  Undefined property:  PropertyAccessClass::$PropertyChanged in <b>C:\ftproot\pnet\test2.php</b> on line <b>22</b><br />
<br />
<b>Notice</b>:  Undefined property:  PropertyAccessClass::$DefaultProperty in <b>C:\ftproot\pnet\test2.php</b> on line <b>33</b><br />
before set : <br>
after set  : propertyValue<br>
PropertyAccessClass Object
(
    [property:private] => propertyValue
    [defaultProperty:private] => default
    [changed:private] => 
    [PropertyChanged] => 1
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-15 05:59 UTC] csmoak at andrew dot cmu dot edu
This really should be taken care of.
 [2004-07-15 11:48 UTC] derick@php.net
It's still a feature request.
 [2005-08-15 12:14 UTC] ilia at manual dot ru
This is a really annoying issue. I actually was frustrated by it when the whole system was already ready 'on paper'.


You can set a border of e.g 1000 calls to catch the infinite recursion, if you wish but one shouldn't catch programmer's hand - let him have the recursion if he wants to!

The current behaviour is USELESS, while allowing recursive calls is HELPFUL.

This seems quite a reason to fix that..
 [2006-03-01 08:30 UTC] tony2001@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: Mon Feb 26 08:01:27 2024 UTC