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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 02:01:36 2025 UTC