Hi!

I've never posted on internal before, but I've been a long time reader
of it. I've been using PHP for a long time, I think it all started
back in 2000 sometime, anyway - this is hardly a place to put my
entire php biography up for show, so I'll jump right to the action.

Ever since PHP5 and the much improved object model (exceptions, and
what not) there has been one thing missing (at least for me) the whole
time. When you call a method (and function, but this doesn't really
matter from an OO perspective) on an object that does not exist, you
get a "Fatal error: Call to undefined method Foo::bar() in
C:\www\index.php on line 4".

What I would like to argue/request is that there should be a way to
get an exception thrown when you call a non existent method on an
object, since it's not possible to catch E_ERROR with a user defined
function using set_error_handler() I can't see anyway to accomplish
this in the current implementation?

Why do you want this? To allow for "true" duck typing (which I think
fits good into PHP's dynamic nature) without having the risk of your
application running into fatal errors and now having to use
if(method_exists($obj, $method)) on every call I want to make.

I've come up with a couple of suggestions on how this could be
implemented, but I'm not very good with the inner workings of php /
zend engine (I've read parts of Saras book, but that's about it) so I
don't know how hard (or easy) any of these suggestions would be to
implement:


a) Change the error raised when running into an unknown method call
into it's own type that is fatal if not caught by an user defined
error handler?

b) Change the error raised to E_WARNING

c) Change the error raised to E_RECOVERABLE_ERROR which as far as I
can make out is possible to handle with a user defined error handler?

d) Make the engine throw an exception of a special type when an
unknown method is called, possibly provide an php.ini-setting so you
can toggle between the old (E_ERROR) and the new
(UnkownMethodException) to not break BC?


Thanks for reading my message, regards Fredrik.

Reply via email to