|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 13:00:01 2025 UTC |
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(); } };