From:             johnny at eiole dot com
Operating system: Windows
PHP version:      5.2.6
PHP Bug Type:     Class/Object related
Bug description:  Reference and key() problem

Description:
------------
When an static array if retourned from a method, for iterating, and
acceded with the key() function, the reference pointer is moved to the end
of the array.

After the loop, the array is unaccessible.

Important : if you add the following line : 

$tab = testbug::getTab();

before the loop, the error does not occur.

you can use key(), current(), prev(), there is still a bug.

First tested on windows 5.2.5 version, and still present on 5.2.6
version.

There is no bug on 5.2.3 version.

Thanks for answer.



Reproduce code:
---------------
<?php
class testbug
{
        static $tab = array(
                'k1' => "elm1",
                'k2' => "elm2",
                'k3' => "elm3",
                'k4' => "elm4",
        );
        
        static function getTab()
        {
                return self::$tab;
        }
}

var_dump(testbug::getTab());
foreach (testbug::getTab() as $k => $v)
{
        key(testbug::getTab());
}
var_dump(testbug::getTab());

Expected result:
----------------
array
  'k1' => string 'elm1' (length=4)
  'k2' => string 'elm2' (length=4)
  'k3' => string 'elm3' (length=4)
  'k4' => string 'elm4' (length=4)

array
  'k1' => string 'elm1' (length=4)
  'k2' => string 'elm2' (length=4)
  'k3' => string 'elm3' (length=4)
  'k4' => string 'elm4' (length=4)


Actual result:
--------------
array
  'k1' => string 'elm1' (length=4)
  'k2' => string 'elm2' (length=4)
  'k3' => string 'elm3' (length=4)
  'k4' => string 'elm4' (length=4)

null


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

Reply via email to