|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-10-29 11:30 UTC] jani@php.net
[2008-10-29 12:10 UTC] bugzilla at zuavra dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 02:00:01 2025 UTC |
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