From:             skarab at versus-clash dot com
Operating system: Linux 2.6 / Windows XP
PHP version:      5.2.6
PHP Bug Type:     Class/Object related
Bug description:  array_walk and array_walk_recursive can alter 
private/protected object variable

Description:
------------
array_walk and array_walk_recursive can alter private and protected object
/ class variables outside the scope of the object / class.

Reproduce code:
---------------
class Some_Class
{
    public $public = 'public string';
    protected $_protected = 'protected string';
    private $_private = 'private string';
}

function some_function(&$item, $key)
{
    $item = 'public access';
}

$Somme_Class = new Some_Class();
array_walk($Somme_Class, 'some_function');
echo '<pre>' . print_r($Somme_Class, true) . '</pre>';

$Another_Class = new Some_Class();
array_walk_recursive($Another_Class, 'some_function');
echo '<pre>' . print_r($Another_Class, true) . '</pre>';

Expected result:
----------------
Some_Class Object
(
    [public] => public access
    [_protected:protected] => protected string
    [_private:private] => protected string
)

Some_Class Object
(
    [public] => public access
    [_protected:protected] => protected string
    [_private:private] => private string
)

or an error message like : 
Fatal error: Cannot access protected property Some_Class::$_protected
or 
Warning: array_walk() expects parameter 1 to be array, object given

Actual result:
--------------
Some_Class Object
(
    [public] => public access
    [_protected:protected] => public access
    [_private:private] => public access
)

Some_Class Object
(
    [public] => public access
    [_protected:protected] => public access
    [_private:private] => public access
)


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

Reply via email to