set_exception_handler()

php.internals

Timm Friebe

22 years ago
Hello, I wanted to check back on the status of my patch to zend_builtin_functions.c I sent a while ago. It changes set_exception_handler() to accept the pseudo-type "callable" (instead of a string referring to a global function). Examples: set_exception_handler('function_name'); set_exception_handler(array('class_name', 'static_method')); set_exception_handler(array($instance, 'instance_method')); This also makes set_exception_handler() more consistent with all the other callback functionality, e.g. set_error_handler(). Will this patch make it into CVS? - Timm

Andi Gutmans

22 years ago
In general, I have no problem with adding this consistency. Where is a reference to $instance held until the exception occurs? I took a quick look and couldn't see it but I'm probably missing something. Andi At 08:13 PM 4/3/2004 +0200, Timm Friebe wrote:

Timm Friebe

22 years ago
On Sat, 2004-04-03 at 21:26, Andi Gutmans wrote:
> In general, I have no problem with adding this consistency. > Where is a reference to $instance held until the exception occurs?
What kind of reference? This is what I used to verify the (instance) functionality: <?php class ExceptionHandler { protected $prefix = '*** Uncaught exception'; public function handle($e) { printf( "%s: %s (%s)\n", $this->prefix, get_class($e), $e->getMessage() ); } } $handler= new ExceptionHandler(); set_exception_handler(array($handler, 'handle')); throw(new Exception('Test')); ?> Output: *** Uncaught exception: exception (Test) - Timm

Andi Gutmans

22 years ago
Never mind. I checked the source and saw what I was looking for (that the handler also preserves the object instance and not just the method itself). I applied your patch. Thanks. At 11:34 PM 4/3/2004 +0200, Timm Friebe wrote: