Bug #62985 [Com]: set_exception_handler doesn't work from command line
| From: | kastaneda at gmail dot com | Date: | Thu, 03 Nov 2016 10:24:51 +0000 |
| Subject: | Bug #62985 [Com]: set_exception_handler doesn't work from command line | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-205168@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62985&edit=1
ID: 62985
Comment by: kastaneda at gmail dot com
Reported by: lgandras at gmail dot com
Summary: set_exception_handler doesn't work from command line
Status: Wont fix
Type: Bug
Package: *Configuration Issues
Operating System: CentoOS 6.2 x64
PHP Version: 5.3.16
Block user comment: N
Private report: N
New Comment:
The same incorrect behavior in interactive mode:
$ php -a
Interactive mode enabled
php > set_exception_handler(function(){echo "catched\n";});
php > throw new Exception;
PHP Warning: Uncaught Exception in php shell code:1
Stack trace:
#0 {main}
thrown in php shell code on line 1
php > ^D
$ php -v
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies
$
Previous Comments:
------------------------------------------------------------------------
[2015-05-13 20:54:19] daniel dot beardsley at gmail dot com
Just ran into this same issue.
I'm suspicious that this isn't the only thing that just *doesn't* work when run from
'php -r'
------------------------------------------------------------------------
[2014-07-26 19:38:34] php at PointedEars dot de
I see the same in PHP 5.6.0RC2 on Debian GNU/Linux. This does not appear to be a configuration issue
as the same script handles the exception when run with CLI as a file with the *same* configuration.
The manual does not say anything about that, but someone reported the this problem in the user
comments 8 years ago. Why is this bug marked WONTFIX?
Steps to reproduce the problem (from bash command line):
$ cat php55-exceptions.php
<?php
set_exception_handler(function (Exception $ex) {
echo 42 . PHP_EOL;
});
throw new Exception();
$ sed -n '2,$p' php55-exceptions.php
set_exception_handler(function (Exception $ex) {
echo 42 . PHP_EOL;
});
throw new Exception();
$ php -r "$(sed -n '2,$p' php55-exceptions.php)"
PHP Fatal error: Uncaught exception 'Exception' in Command line code:6
Stack trace:
#0 {main}
thrown in Command line code on line 6
$ php php55-exceptions.php
42
Versions and configuration:
$ php -r 'phpinfo(INFO_GENERAL);'
phpinfo()
PHP Version => 5.6.0RC2
System => Linux pe-mobil2.localdomain 3.4.87-pe #1 SMP Mon Apr 21 15:20:23 CEST 2014 i686
Build Date => Jul 22 2014 22:49:54
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
Scan this dir for additional .ini files => /etc/php5/cli/conf.d
Additional .ini files parsed => /etc/php5/cli/conf.d/05-opcache.ini,
/etc/php5/cli/conf.d/10-pdo.ini,
/etc/php5/cli/conf.d/20-curl.ini,
/etc/php5/cli/conf.d/20-gd.ini,
/etc/php5/cli/conf.d/20-imagick.ini,
/etc/php5/cli/conf.d/20-intl.ini,
/etc/php5/cli/conf.d/20-json.ini,
/etc/php5/cli/conf.d/20-mcrypt.ini,
/etc/php5/cli/conf.d/20-memcache.ini,
/etc/php5/cli/conf.d/20-mysql.ini,
/etc/php5/cli/conf.d/20-mysqli.ini,
/etc/php5/cli/conf.d/20-pdo_mysql.ini,
/etc/php5/cli/conf.d/20-readline.ini,
/etc/php5/cli/conf.d/20-xdebug.ini,
/etc/php5/cli/conf.d/20-xsl.ini
PHP API => 20131106
PHP Extension => 20131226
Zend Extension => 220131226
Zend Extension Build => API220131226,NTS
PHP Extension Build => API20131226,NTS
Debug Build => no
Thread Safety => disabled
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => enabled
Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data,
http, ftp, phar, zip
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1,
tlsv1.2
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper,
string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.6.0-dev, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick Rethans
$ dpkg -l 'php5*' | awk '/^.i/ {print $2, $3}'
php5 5.6.0~rc2+dfsg-5
php5-apcu 4.0.6-1
php5-cgi 5.6.0~rc2+dfsg-5
php5-cli 5.6.0~rc2+dfsg-5
php5-common 5.6.0~rc2+dfsg-5
php5-curl 5.6.0~rc2+dfsg-5
php5-gd 5.6.0~rc2+dfsg-5
php5-imagick 3.1.2-1+b1
php5-intl 5.6.0~rc2+dfsg-5
php5-json 1.3.5-3
php5-mcrypt 5.6.0~rc2+dfsg-5
php5-memcache 3.0.8-4+b1
php5-mysql 5.6.0~rc2+dfsg-5
php5-readline 5.6.0~rc2+dfsg-5
php5-xdebug 2.2.4-1+b1
php5-xsl 5.6.0~rc2+dfsg-5
Changes to php.ini:
$ diff -u /usr/share/php5/php.ini-production.cli /etc/php5/cli/php.ini
--- /usr/share/php5/php.ini-production.cli 2014-07-23 01:11:03.000000000 +0200
+++ /etc/php5/cli/php.ini 2014-06-02 13:05:31.000000000 +0200
@@ -83,8 +83,6 @@
; development version only in development environments, as errors shown to
; application users can inadvertently leak otherwise secure information.
-; This is php.ini-production INI file.
-
;;;;;;;;;;;;;;;;;;;
; Quick Reference ;
;;;;;;;;;;;;;;;;;;;
@@ -231,7 +229,7 @@
; Development Value: 4096
; Production Value: 4096
; http://php.net/output-buffering
-output_buffering = 4096
+output_buffering = Off
; You can redirect all of the output of your scripts to a function. For
; example, if you set output_handler to "mb_output_handler", character
@@ -276,7 +274,7 @@
; implications and is generally recommended for debugging purposes only.
; http://php.net/implicit-flush
; Note: This directive is hardcoded to On for the CLI SAPI
-max_execution_time = 30
+max_execution_time = 30000
; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
@@ -710,6 +708,7 @@
; UNIX: "/path1:/path2"
;include_path = ".:/usr/share/php"
+include_path = ".:/usr/share/php:/home/pelinux/LCARS/scripts/php"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
@@ -882,7 +881,7 @@
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
-;date.timezone =
+date.timezone = Europe/Zurich
; http://php.net/date.default-latitude
;date.default_latitude = 31.7667
@@ -1686,7 +1685,6 @@
; http://php.net/mbstring.language
;mbstring.language = Japanese
-; Use of this INI entry is deprecated, use global internal_encoding instead.
; internal/script encoding.
; Some encoding cannot work as internal encoding. (e.g. SJIS, BIG5, ISO-2022-*)
; If empty, default_charset or internal_encoding or iconv.internal_encoding is used.
Backtrace:
I do not have a debug build of PHP. Please tell me if I need to make one in this case (not a PHP
crash).
------------------------------------------------------------------------
[2012-09-04 14:46:40] laruence@php.net
since you have got a alternative way,, then I'd like this be marked as wont'fix
------------------------------------------------------------------------
[2012-08-31 18:14:42] lgandras at gmail dot com
Temporary solution
echo '<?php set_exception_handler(function($e){echo "catched\n";});throw new
Exception;' | /usr/local/bin/php
------------------------------------------------------------------------
[2012-08-31 17:29:57] laruence@php.net
The following patch has been added/updated:
Patch Name: bug62985.patch
Revision: 1346434197
URL: https://bugs.php.net/patch-display.php?bug=62985&patch=bug62985.patch&revision=1346434197
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=62985
--
Edit this bug report at https://bugs.php.net/bug.php?id=62985&edit=1