From:             bugzilla at zuavra dot net
Operating system: Windows XP, but probably irrelev
PHP version:      5.3.0alpha2
PHP Bug Type:     Scripting Engine problem
Bug description:  each() erratic behaviour with objects

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 bug report at http://bugs.php.net/?id=46416&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=46416&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=46416&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=46416&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=46416&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=46416&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=46416&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=46416&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=46416&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=46416&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=46416&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=46416&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=46416&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=46416&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=46416&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=46416&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=46416&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=46416&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=46416&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=46416&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=46416&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=46416&r=mysqlcfg

Reply via email to