php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46305 Exception handler not invoked when using -r command line option
Submitted: 2008-10-15 15:42 UTC Modified: 2009-04-21 10:34 UTC
From: jbq at caraldi dot com Assigned:
Status: Not a bug Package: CGI/CLI related
PHP Version: 5CVS-2008-10-24 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jbq at caraldi dot com
New email:
PHP Version: OS:

 

 [2008-10-15 15:42 UTC] jbq at caraldi dot com
Description:
------------
When using the "-r" or "-run" command-line option to execute code, a custom exception handler is not invoked.

Reproduce code:
---------------
$ cat command_line_exception_handler.php
<?
function handler($e) {
    print "Caught exception " . $e->getMessage() . "\n";
}
set_exception_handler("handler");
throw new Exception("Hello, World!");


Expected result:
----------------
$ php command_line_exception_handler.php
Caught exception Hello, World!

$ php -r "require 'command_line_exception_handler.php';"
Caught exception Hello, World!

Actual result:
--------------
$ php command_line_exception_handler.php
Caught exception Hello, World!

$ php -r "require 'command_line_exception_handler.php';"

Fatal error: Uncaught exception 'Exception' with message 'Hello, World!' in /home/jbq/command_line_exception_handler.php:6
Stack trace:
#0 Command line code(1): require()
#1 {main}
  thrown in /home/jbq/command_line_exception_handler.php on line 6


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-21 10:34 UTC] jani@php.net
Like said in manual page for CLI: "Note: This option is meant for a very basic stuff." http://php.net/cli

What you're doing isn't basic.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC