php.net |  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: chregu@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2006-07-19 (CVS) OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chregu@php.net
New email:
PHP Version: OS:

 

 [2006-07-19 16:14 UTC] chregu@php.net
Description:
------------
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 http://bugs.php.net/bug.php?id=38102, except 
that i don't write to the arrray and on the other bug he 
does


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

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

$f = new foo();

//error
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-24 07:44 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_2.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Feb 03 18:01:32 2025 UTC