#45281 [Asn->Bgs]: each on objects shows private and protected properties

From: Date: Fri, 13 Feb 2009 23:01:57 +0000
Subject: #45281 [Asn->Bgs]: each on objects shows private and protected properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-133814@lists.php.net to get a copy of this message
 ID:               45281
 Updated by:       felipe@php.net
 Reported By:      kopelke at gmail dot com
-Status:           Assigned
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: *
 PHP Version:      5.2.6
 Assigned To:      helly
 New Comment:

See http://derickrethans.nl/private_properties_exposed.php


Previous Comments:
------------------------------------------------------------------------

[2008-07-06 01:26:29] jani@php.net

Assigned to Marcus who (IIRC) implemented this PPP stuff.

------------------------------------------------------------------------

[2008-06-16 14:50:04] kopelke at gmail dot com

Description:
------------
If each is used on an object it will reveal the protected and private
member data. It is not possible to change this data, but it should not
be visible at all.
Besides the each function should not be allowed on objects, or, if
implementing ArrayAccess, it should not reveal the private and protected
properties.

Reproduce code:
---------------
class A {
	private $x = 'private';
	protected $y = 'protected';
	public $z = 'public';
}

$o = new A();
$o -> a = 'outer:public';

while(list($k, $v) = each($o)) {
	$pos = 0;
	if($k{0} == "\0") 
		$k = substr($k, $pos = strpos($k, "\0", 1) + 1);
	switch($pos) {
		case 6:
			$k = 'Private::' . $k; break;
		case 3:
			$k = 'Protected::' . $k; break;
		default:
			$k = 'Public::' . $k; break;
	}
	echo '<pre>'; print_r(array($k, $v)); echo '</pre>';
}

Expected result:
----------------
Array
(
    [0] => Public::z
    [1] => public
)

Array
(
    [0] => Public::a
    [1] => outer:public
)

Actual result:
--------------
Array
(
    [0] => Protected::x
    [1] => private
)

Array
(
    [0] => Protected::y
    [1] => protected
)

Array
(
    [0] => Public::z
    [1] => public
)

Array
(
    [0] => Public::a
    [1] => public von aussen
)



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45281&edit=1



Thread (3 messages)

« previous php.bugs (#133814) next »