From:             yubing at cernet dot edu dot cn
Operating system: Redhat Linux 8.0
PHP version:      4.3.10
PHP Bug Type:     Scripting Engine problem
Bug description:  foreach without "$key =>" is not compatible with pre-versions

Description:
------------
foreach on array containing objects without "$key =>" is not compatible
with pre-versions

Is that because of the porting of those code from v5.0.2 ?

b2evo and xoops use many this kind of statements to fetch the database
objects.

Reproduce code:
---------------
$a = array();
$user->name = "peter";
$user->age = "24";
$a[0] = $user;
$user->name = "ice";
$user->age = "25";
$a[1] = $user;

    foreach ( $a as $u){
    // foreach ( $a as $key => $u) works ok
    print $u->name.": ".$u->age."\n";
        var_dump($u);
    }


Expected result:
----------------
peter:24
ice:25
object(stdClass)(2) {
  ["name"]=>
  string(5) "peter"
  ["age"]=>
  string(2) "24"
}
object(stdClass)(2) {
  ["name"]=>
  string(3) "ice"
  ["age"]=>
  string(2) "25"
}

Actual result:
--------------
NULL:NULL
NULL:NULL
array(2) {
  [0]=>
  object(stdClass)(2) {
    ["name"]=>
    string(5) "peter"
    ["age"]=>
    string(2) "24"
  }
  [1]=>
  int(0)
}
array(2) {
  [0]=>
  object(stdClass)(2) {
    ["name"]=>
    string(3) "ice"
    ["age"]=>
    string(2) "25"
  }
  [1]=>
  int(1)
}

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

Reply via email to