From:             agostone at freemail dot hu
Operating system: Windows Xp
PHP version:      5.2.5
PHP Bug Type:     Scripting Engine problem
Bug description:  Calling parent::__set when __set  is overloaded = 
parent->child->parent calls

Description:
------------
If i have an overloaded __set function in a class and call parent::__set
from another function, the parent calls the child's __set back and a loop
gets created like this:

parent::__set (initial call)
child::_set
parent::_set

I need __set function to do some prefixing by default when assigning new
string properties by default, i need a custom function to assign
un-prefixed properties too, if there is a need (will happen very rarely)...
I need this to auto prefix string variables passed to my view object (they
gotta be passed as object properties), the MVC framework is a 3rd party
framework, i'm extending it's view object and i don't want to modify the
original source...

Reproduce code:
---------------
<?php 

class A
{
        public function __set($pKey, $pValue)
        {
                echo("Class: ".get_class()."| Passed Value:".$pValue."<BR>");
                $this->$pKey = $pValue;
                return true;
        }
}

class B extends A
{
        function setRaw($pKey, $pValue)
        {
                parent::__set($pKey, $pValue);
        }

        function __set($pKey, $pValue)
        {
                echo("Class: ".get_class()."| Passed Value:".$pValue."<BR>");
                $pValue = $this->prefix($pValue);
                parent::__set($pKey, $pValue);
        }

        function prefix($pValue)
        {
                if(is_string($pValue))
                {
                        return "(prefixed) ".$pValue;
                }
                return $pValue;
        }
}

$b = new B();

echo("Calling: setRaw()<br>");
$b->setRaw("raw", "shouldn't be prefixed");
echo("<br>");

echo("Calling: __set()<br>");
$b->prefixed = "should be prefixed";

echo("<br>Variable after setraw: ".$b->raw);
echo("<br>Variable after set: ".$b->prefixed);
echo("<br>");

?>

Expected result:
----------------
Calling: setRaw()
Class: A| Passed Value:shouldn't be prefixed

Calling: __set()
Class: B| Passed Value:should be prefixed
Class: A| Passed Value:(prefixed) should be prefixed

Variable after setRaw: shouldn't be prefixed
Variable after set: (prefixed) should be prefixed


Actual result:
--------------
Calling: setRaw()
Class: A| Passed Value:shouldn't be prefixed
Class: B| Passed Value:shouldn't be prefixed
Class: A| Passed Value:(prefixed) shouldn't be prefixed

Calling: __set()
Class: B| Passed Value:should be prefixed
Class: A| Passed Value:(prefixed) should be prefixed

Variable after setraw: (prefixed) shouldn't be prefixed
Variable after set: (prefixed) should be prefixed


-- 
Edit bug report at http://bugs.php.net/?id=44807&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=44807&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=44807&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=44807&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=44807&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=44807&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=44807&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=44807&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=44807&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=44807&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=44807&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=44807&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=44807&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=44807&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=44807&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=44807&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=44807&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=44807&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=44807&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=44807&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=44807&r=mysqlcfg

Reply via email to