From:             wkonkel at gmail dot com
Operating system: n/a
PHP version:      5.0.4
PHP Bug Type:     *General Issues
Bug description:  __get and __set don't handle arrays correctly

Description:
------------
The __set and __get don't seem to handle arrays correctly.  What's even
worse, is it adds data to memory which is allocated at a later time ($boz
gets foo2 and foo3 of $myObj).  The code example speaks for itself.  

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

class buggy {
        private $data;
        function __set($key, $val) {
                $this->data[$key] = $val;
        }
        function __get($key) {
                return $this->data[$key];
        }
}

$myObj = new buggy();
$myObj->somevar['foo1'] = 'bar1';
$myObj->somevar['foo2'] = 'bar2';
$myObj->somevar['foo3'] = 'bar3';

$boz[] = 'blah';
print_r($boz);

?>

Expected result:
----------------
Array
(
    [0] => blah
)

Actual result:
--------------
Array
(
    [foo2] => bar2
    [foo3] => bar3
    [0] => blah
)

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

Reply via email to