php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31214 overloading using __call() initially OK, fails on any subsequent method call
Submitted: 2004-12-21 02:26 UTC Modified: 2005-01-07 09:01 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: ebypdx at comcast dot net Assigned:
Status: No Feedback Package: Class/Object related
PHP Version: 4.3.10 OS: Solaris 5.8
Private report: No CVE-ID: None
 [2004-12-21 02:26 UTC] ebypdx at comcast dot net
Description:
------------
in the most simple case, create a class with no methods except __call() and overload it.  start calling methods on an instance of that class.  the first method call will hit __call() and finish correctly.  any subsequent method calls will fail to hit __call(), resulting instead in a fatal error.

if this is indeed a bug... i realize due to the experimental nature of overloading in 4.3, that this may never work again.  my deepest thanks to anybody who can address this.

Reproduce code:
---------------
<?php
class BaseOverloader {
    function BaseOverloader() {}
    function __call($method, $args, &$returnValue) {
        echo "Call to ".get_class($this)."->$method <br/>";
        $returnValue = "return";
        return true;
    }
}
overload("BaseOverloader");
$c = new BaseOverloader();
$c->firstCall();
$c->secondCall();
?>

Expected result:
----------------
Call to BaseOverloader->firstcall
Call to BaseOverloader->secondcall

Actual result:
--------------
Call to baseoverloader->firstcall

Fatal error: Call to a member function on a non-object in /export/vol01/opt/web/neby/partner.newedgenetworks.com/overloaded.php on line 13


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-21 02:28 UTC] ebypdx at comcast dot net
I've also seen it fail out with a different fatal error "call to undefined function".  i can't determine how to make it do this instead of giving "call on a non-object."
 [2004-12-21 02:35 UTC] alan_k@php.net
a) make sure you are not using any Zend extension eg. Optimizer/xdebug/apc etc. 

have a look at this report 
http://bugs.php.net/?id=31106

see if reverting the mentioned change to zend_execute fixes this.
 [2004-12-21 02:45 UTC] ebypdx at comcast dot net
i believe we aren't using any of those extensions.  i will double-check with the sysadmin team.

can you give me a tip on how to revert that change?  when i follow the link to cvsweb from report 31106 i get a "malformed query" page.
 [2004-12-21 03:04 UTC] alan_k@php.net
in Zend/zend_execute.c

about line 997: remove this line 	
	PZVAL_UNLOCK(T->EA.data.overloaded_element.object);

about line 1579: remove this line

        EX(object).ptr->refcount++;

you have to copy & paste the whole link for it to work / rather than just pressing on it.

 [2004-12-21 03:58 UTC] iliaa@php.net
Try the patch listed in bug report #31106
 [2004-12-21 17:33 UTC] ebypdx at comcast dot net
thanks very much for the feedback, if our sysadmins have time to apply that patch i'll post back the results.  for now we've rolled back a version.
 [2004-12-21 18:05 UTC] iliaa@php.net
leave bug @ feedback until further information is known.
 [2004-12-29 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-01-07 03:41 UTC] patrick at arkeon dot com
A "not real" solution about the "Call to a member function on a non-object"

Try this:
// Only to avoid the problem...
class Dummy { 
	function Dummy() {
	}
}
$toto =& new Dummy();

class BaseOverloader {
    function BaseOverloader() {}
    function __call($method, $args, &$returnValue) {
        echo "Call to ".get_class($this)."->$method <br/>";
        $returnValue = "return";
        return true;
    }
}
overload("BaseOverloader");
$toto = new BaseOverloader();
$toto->firstCall();
$toto->secondCall();

Then you got:
Call to baseoverloader->firstcall 
Call to baseoverloader->secondcall 

Weird, no?!?
 [2005-01-07 09:01 UTC] alan_k@php.net
try snaps.php.net - this should be fixed now.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC