|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38146 Cannot use array returned from foo::__get('bar') in write context
Submitted: 2006-07-19 16:14 UTC Modified: 2006-07-24 07:44 UTC
From: Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2006-07-19 (CVS) OS: all
Private report: No CVE-ID: None
 [2006-07-19 16:14 UTC]
When looping through an array, returned by a __get method, 
the following error appears:

"Fatal error: Cannot use array returned from foo::__get
('bar') in write context" 

Worked in 5.1

Would be nice, if that could be fixed, as there's no write 
done in this case and it's a pretty annoying BC break.

Although one can avoid it with:

$f = new foo();
$a = $f->bar;
foreach($a as $key => $value) {}

so there's at least a workaround.

BTW, similar to, except 
that i don't write to the arrray and on the other bug he 

Reproduce code:

class foo {
    public function __get($member) {
        $f = array("foo"=>"bar","bar"=>"foo");
        return $f;

$f = new foo();

foreach($f->bar as $key => $value) {
    print "$key => $value";

Expected result:
foo => bar
bar => foo

Actual result:
Fatal error: Cannot use array returned from foo::__get('bar') 
in write context


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-24 07:44 UTC]
Fixed in CVS HEAD and PHP_5_2.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed May 12 20:01:28 2021 UTC