php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31205 foreach fails on arrays of objects
Submitted: 2004-12-20 17:02 UTC Modified: 2004-12-20 17:34 UTC
From: cjlars at users dot sourceforge dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.10 OS: Linux 2.4.21 (only one tested)
Private report: No CVE-ID: None
 [2004-12-20 17:02 UTC] cjlars at users dot sourceforge dot net
Description:
------------
The below code should obviously return "aaaaaaa". With PHP 4.3.10 is returns nothing.
It does return the expected result if I use:
 foreach ($arr_test as $key => $objtest)
I think in the code below $objtest is an array instead of being an onject.

This is critical and it affects lots of existing code (I've seen NuSOAP affected for example)

Reproduce code:
---------------
<?php

class test_class
{
    var $test;
}

$arr_test = array();
$obj = new test_class();
$obj->test = "aaaaaa";
$arr_test[] = $obj;

foreach ($arr_test as $objtest)
    echo $objtest->test;

?>

Expected result:
----------------
aaaaaa

Actual result:
--------------
Nothing

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-20 17:33 UTC] tony2001@php.net
Do not file bugs when you have Zend extensions (zend_extension=)
loaded. Examples are Zend Optimizer, Zend Debugger, Turck MM Cache,
APC, Xdebug and ionCube loader.  These extensions often modify engine
behavior which is not related to PHP itself.


 [2004-12-20 17:34 UTC] derick@php.net
Do not file bugs when you have Zend extensions (zend_extension=)
loaded. Examples are Zend Optimizer, Zend Debugger, Turck MM Cache,
APC, Xdebug and ionCube loader.  These extensions often modify engine
behavior which is not related to PHP itself.

Also, search the bug database first before filing a bug!
And this Zend extension thing is marked in read on the "report" page, should we make it a h1 and blinking perhaps?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Aug 15 15:01:27 2024 UTC