php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28713 crash in recursive call of __call
Submitted: 2004-06-09 20:05 UTC Modified: 2004-06-10 19:34 UTC
From: rodolfo at rodsoft dot org Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.0.0RC2 OS: linux 2.6.6
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: rodolfo at rodsoft dot org
New email:
PHP Version: OS:

 

 [2004-06-09 20:05 UTC] rodolfo at rodsoft dot org
Description:
------------
This ill-behaved code crashes php. I know one should never write things like this, but this sample is an oversimplified version of a much bigger code I'm working with, and I've just spot my error after trying to simplify the code to attach here. PHP should emmit a warning when such things happen, as with __set and __get, saying that $this->func() isn't defined, when called inside a __call handler.

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

class test
{
    function __call($func, $args)
    {
	$this->hello();
    }
}

$a = new test;
$a->hello();
echo "You won't read this";

?>


Expected result:
----------------
A warning saying that $this->hello isn't defined.

Actual result:
--------------
The coredump is a bunch of

#0 0x0821d843 in zend_call_function ()
#1 0x0821e76a in call_user_function_ex ()
#2 0x0823cfa5 in zend_std_call_user_call ()
#3 0x0825f8ee in zend_do_fcall_common_helper ()
#4 0x0825faf1 in zend_do_fcall_by_name_handler ()
#5 0x0824daf8 in execute ()

repeated over and over

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-10 08:58 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The only way in which PHP is allowed to crash is in this case: unlimited recursive calling of functions. 
 [2004-06-10 19:34 UTC] rodolfo at rodsoft dot org
You're right, but the __set and __get functions manage to get around this problem by not allowing you to access an undefined property inside them (which would cause recursive calling of itself). Wouldn't it be logical to extend this behaviour to __call, not allowing one to call an undefined member inside it? The way it is now can lead to situations like this:

class myclass
{
    function test() {} // Comment this line out and php
                       // will crash. Very hard bug to trace
                       // when working on a big class.

    function __call($func, $args)
    {
        $this->test();
    }
};
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 04 14:00:01 2025 UTC