ID: 45937 Updated by: [EMAIL PROTECTED] Reported By: skarab at versus-clash dot com -Status: Assigned +Status: Closed Bug Type: Arrays related Operating System: Linux 2.6 / Windows XP PHP Version: 5.2.6 Assigned To: felipe New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Fixed in 5_3 and HEAD. Now it works only with arrays. Thanks. Previous Comments: ------------------------------------------------------------------------ [2008-08-27 16:05:22] skarab at versus-clash dot com 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 this bug report at http://bugs.php.net/?id=45937&edit=1