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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC