#46416 [Opn->Bgs]: each() erratic behaviour with objects

From: Date: Wed, 29 Oct 2008 11:30:54 +0000
Subject: #46416 [Opn->Bgs]: each() erratic behaviour with objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-130274@lists.php.net to get a copy of this message
ID: 46416 Updated by: jani@php.net Reported By: bugzilla at zuavra dot net -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.3.0alpha2 New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Previous Comments: ------------------------------------------------------------------------ [2008-10-29 10:06:26] bugzilla at zuavra dot net Description: ------------ Using each() to iterate through an object will produce weird results in two respects: 1. It will expose private and protected members alongside public ones. 2. For private and protected members, the keys (names) are jumbled. Yes, I know that this behaviour is known and that the manual page for each() warns about this. But such an inconsistency should not exist. Desirable consistent behaviour: a) Produce the same results as foreach() (show only public members). or b) Refuse to work with objects altogether and state so in the manual. Reproduce code: --------------- <?php class Example { private $priv = 1; protected $prot = 2; public $pub = 3; } $obj = new Example(); while (list($key, $val) = each($obj)) { printf("%s = %s\n", $key, $val); } ?> Expected result: ---------------- pub = 3 Actual result: -------------- [NUL]Example[NUL]priv = 1 [NUL]*[NUL]prot = 2 pub = 3 where [NUL] is the null (0x00) character ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46416&edit=1

« previous php.bugs (#130274) next »