Edit report at https://bugs.php.net/bug.php?id=45937&edit=1
ID: 45937
Comment by: shurph at gmail dot com
Reported by: skarab at versus-clash dot com
Summary: array_walk and array_walk_recursive can alter
private/protected object variable
Status: Closed
Type: Bug
Package: Arrays related
Operating System: Linux 2.6 / Windows XP
PHP Version: 5.2.6
Assigned To: felipe
Block user comment: N
Private report: N
New Comment:
In php 5.3.5 this problem enabled, too.
Details about environment:
PHP Version 5.3.5-1ubuntu7.7 with the Suhosin Patch 0.9.10
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
Ubuntu 10.04
Linux localhost 2.6.38-13-generic-pae #56-Ubuntu SMP Tue Feb 14 14:32:30 UTC
2012 i686
Previous Comments:
------------------------------------------------------------------------
[2008-08-29 03:13:38] [email protected]
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.
------------------------------------------------------------------------
[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 https://bugs.php.net/bug.php?id=45937&edit=1