php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35651 Recursive call to setter "blocks" the property
Submitted: 2005-12-12 21:20 UTC Modified: 2005-12-12 21:28 UTC
From: tomas_matousek at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.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: tomas_matousek at hotmail dot com
New email:
PHP Version: OS:

 

 [2005-12-12 21:20 UTC] tomas_matousek at hotmail dot com
Description:
------------
In the following example, the __setter invoked by $x->a = "g1"; statement tries to write to "a" property again by $this->a = "a"; statement in the switch. This latter access is correctly considered to be recursive and thus treated as assignment to $this->a and not as a recursive call. That's ok. However, after returning from the __setter and when invoking it again by $x->b = "g2"; the $this->a = "b"; should call the __setter because we it is not a recursive call ("b" was accessed, not "a"). Hence $this->a = "b"; should invoke __setter in this case. And that doesn't happen.

Reproduce code:
---------------
class C
{
    function __set($f,$v)
    {
        echo "set('$f','$v')\n";
        switch ($f)
        {
            case "a": $this->a = "a"; break;
            case "b": $this->a = "b"; break;
        }
    }
}
$x = new C;
$x->a = "g1"; // this blocks "a" on $x forever
$x->b = "g2";

Expected result:
----------------
set('a','g1')
set('b','g2')
set('a','b')




Actual result:
--------------
set('a','g1')
set('b','g2')




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-12 21:28 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

__set() and __get() are called only if such property doesn't exist.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 16:01:36 2024 UTC