Edit report at https://bugs.php.net/bug.php?id=30959&edit=1

 ID:                 30959
 Comment by:         michael at unsolicted dot yahoo dot com
 Reported by:        joel at zmail dot pt
 Summary:            __call does not return by reference
 Status:             Bogus
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   *
 PHP Version:        5CVS-2005-03-09
 Assigned To:        andi
 Block user comment: N
 Private report:     N

 New Comment:

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!


Previous Comments:
------------------------------------------------------------------------
[2005-06-19 02:28:03] sni...@php.net

PHP Strict Standards:  Only variables should be assigned by reference


------------------------------------------------------------------------
[2005-03-09 01:00:30] sni...@php.net

Andi, is this the final call? :)
(documentation or engine change..that is the question)


------------------------------------------------------------------------
[2005-03-08 12:53:29] 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-08 12:50:23] he...@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:01:42] joel at zmail dot pt

I've just tested with latest php 5 (php5-200503080930)
and the problem is not solved.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=30959


-- 
Edit this bug report at https://bugs.php.net/bug.php?id=30959&edit=1

Reply via email to