php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30959 __call does not return by reference
Submitted: 2004-12-02 12:43 UTC Modified: 2005-06-19 02:28 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: joel at zmail dot pt Assigned: andi (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5CVS-2005-03-09 OS: *
Private report: No CVE-ID: None
 [2004-12-02 12:43 UTC] joel at zmail dot pt
Description:
------------
__call doesn't return by reference



Reproduce code:
---------------
class A{
    private $x = 123;
    public function  & __call($m,$a){
        return $this->x;
    }
}
$a = new A();
$x = & $a->UndefMethod();
$x = 789;
$y = & $a->UndefMethod();

Expected result:
----------------
$y should be 789, but it is 123


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-08 12:01 UTC] joel at zmail dot pt
I've just tested with latest php 5 (php5-200503080930)
and the problem is not solved.
 [2005-03-08 12:50 UTC] helly@php.net
At the moment __call() relies on the internal signature which is return by copy and the fact that the engine prevents from implementing return by reference functions at c-level.
 [2005-03-08 12:53 UTC] joel at zmail dot pt
well, then that info about __call and return by reference should go into the manual, in the __call section.
right?
 [2005-03-09 01:00 UTC] sniper@php.net
Andi, is this the final call? :)
(documentation or engine change..that is the question)

 [2005-06-19 02:28 UTC] sniper@php.net
PHP Strict Standards:  Only variables should be assigned by reference

 [2011-08-28 08:52 UTC] michael at unsolicted dot yahoo dot com
With all due respect, "only variables should be assigned by reference" makes no sense.

__call does not assign variables.  It executes code for innaccessible methods, and that code may wish to return a reference.

Not bogus; this functionality existed in PHP4 as __call()'s third parameter was passed by reference.

Although this is in no way justification for the fix (as I have already justified it) consider this: (pedantic error checking removed for simplicity)

<?
class Foo
{
    private $world;

    function &__call($method,$params)
    {
        if( substr(0,3,$method) == 'get' )
            return $this->{substr($method,3)};
    }

    function &__get($property)
    {
        return $this->{'get'.$property}();
    }
}

$hello = new Hello;
$hello->world[] = 'php maintainers always say NO';
?>

--which does not work.  For those of us mere 'users' who need this, as a work around try this:

<?
class Hello
{
    . . . include definition from above . . .    

    function &getWorld()
    {
        return $this->world;
    }
}
?>

--which DOES work, although that is not really the point!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC