php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31581 Overloaded property can't be accessed with foreach
Submitted: 2005-01-17 08:00 UTC Modified: 2005-02-02 00:10 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: evert at rooftopsolutions dot nl Assigned: stas (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 4CVS-2005-01-19 OS: Linux 2.4.26
Private report: No CVE-ID: None
 [2005-01-17 08:00 UTC] evert at rooftopsolutions dot nl
Description:
------------
When an array is directly accessed is accessed trough an overloaded class, it works just fine.

When you access it trough foreach, it triggers an error.

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

  class OlClass {

    var $data;

    function OlClass() {

        $this->data = new StdClass();
        $this->data->arr = Array('a','b','c');
        overload('OlClass');

    }

    function __get($p,&$v) {

      $v = $this->data->$p;
      return true;

    }

  }

  $o = new OlClass;

  print_r($o->arr);

  foreach($o->arr as $value) echo($value);

?>

Expected result:
----------------
Array ( [0] => a [1] => b [2] => c )
abc

Actual result:
--------------
Array ( [0] => a [1] => b [2] => c )
Warning: Invalid argument supplied for foreach() in /home/evert/public_html/dev/sabretooth/s41/test/test4.php on line 28

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-17 21:05 UTC] evert at rooftopsolutions dot nl
Did you mean I should test it on the snapshot, or is it solved on the latest snapshot?

I noticed that a commenter on http://nl3.php.net/overload experienced the same problem.
 [2005-01-18 13:09 UTC] evert at rooftopsolutions dot nl
28-Feb-2004 03:45 josh at uncommonprojects dot com
One thing about __get is that if you return an array it doesn't work directly within a foreach...


but we already figured that out :)
 [2005-01-20 00:59 UTC] sniper@php.net
Yet another overload bug..Stas, can you look into this too?

 [2005-02-02 00:10 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 18:01:31 2024 UTC