diff options
author | Dmitry Stogov <dmitry@zend.com> | 2012-09-06 12:14:29 +0400 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2012-09-06 12:14:29 +0400 |
commit | 6ba376f552238de643a665d355fd5e59c40315b5 (patch) | |
tree | d5a066fee542d75ea1c369a8eba1b5caa8f48c72 | |
parent | a43c45ea7d354179df91a59795faa0bcbceb1812 (diff) | |
parent | b29dc146b9311c14186c14bcb1c8ae5288b65d73 (diff) | |
download | php-git-6ba376f552238de643a665d355fd5e59c40315b5.tar.gz |
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3:
- Fixed bug #61767 (Shutdown functions not called in certain error situation) - Fixed bug #60909 (custom error handler throwing Exception + fatal error = no shutdown function)
Conflicts:
NEWS
Zend/zend_object_handlers.c
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | Zend/tests/bug51394.phpt | 6 | ||||
-rw-r--r-- | Zend/tests/bug60909_1.phpt | 24 | ||||
-rw-r--r-- | Zend/tests/bug60909_2.phpt | 20 | ||||
-rw-r--r-- | Zend/tests/bug61767.phpt | 34 | ||||
-rw-r--r-- | Zend/zend.c | 23 | ||||
-rw-r--r-- | Zend/zend_object_handlers.c | 1 |
7 files changed, 112 insertions, 0 deletions
@@ -10,6 +10,10 @@ PHP NEWS . Fixed bug #62955 (Only one directive is loaded from "Per Directory Values" Windows registry). (aserbulov at parallels dot com) . Fixed bug #62907 (Double free when use traits). (Dmitry) + . Fixed bug #61767 (Shutdown functions not called in certain error + situation). (Dmitry) + . Fixed bug #60909 (custom error handler throwing Exception + fatal error + = no shutdown function). (Dmitry) - SOAP . Fixed bug #50997 (SOAP Error when trying to submit 2nd Element of a choice). diff --git a/Zend/tests/bug51394.phpt b/Zend/tests/bug51394.phpt index 537574c9d5..406de13a9b 100644 --- a/Zend/tests/bug51394.phpt +++ b/Zend/tests/bug51394.phpt @@ -13,4 +13,10 @@ function eh() set_error_handler("eh"); $a = $empty($b); --EXPECTF-- +Warning: Uncaught exception 'Exception' with message 'error!' in %sbug51394.php:4 +Stack trace: +#0 %sbug51394.php(9): eh(8, 'Undefined varia...', '%s', 9, Array) +#1 {main} + thrown in %sbug51394.php on line 4 + Fatal error: Function name must be a string in %sbug51394.php on line 9
\ No newline at end of file diff --git a/Zend/tests/bug60909_1.phpt b/Zend/tests/bug60909_1.phpt new file mode 100644 index 0000000000..5150dfc025 --- /dev/null +++ b/Zend/tests/bug60909_1.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #60909 (custom error handler throwing Exception + fatal error = no shutdown function). +--FILE-- +<?php +register_shutdown_function(function(){echo("\n\n!!!shutdown!!!\n\n");}); +set_error_handler(function($errno, $errstr, $errfile, $errline){ + echo "error($errstr)"; + throw new Exception("Foo"); +}); + +require 'notfound.php'; +--EXPECTF-- +error(require(notfound.php): failed to open stream: No such file or directory) +Warning: Uncaught exception 'Exception' with message 'Foo' in %sbug60909_1.php:5 +Stack trace: +#0 %sbug60909_1.php(8): {closure}(2, 'require(notfoun...', '%s', 8, Array) +#1 %sbug60909_1.php(8): require() +#2 {main} + thrown in %sbug60909_1.php on line 5 + +Fatal error: main(): Failed opening required 'notfound.php' (include_path='%s') in %sbug60909_1.php on line 8 + + +!!!shutdown!!! diff --git a/Zend/tests/bug60909_2.phpt b/Zend/tests/bug60909_2.phpt new file mode 100644 index 0000000000..d08d9f90fa --- /dev/null +++ b/Zend/tests/bug60909_2.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #60909 (custom error handler throwing Exception + fatal error = no shutdown function). +--FILE-- +<?php +register_shutdown_function(function(){echo("\n\n!!!shutdown!!!\n\n");}); +set_error_handler(function($errno, $errstr, $errfile, $errline){throw new Exception("Foo");}); + +class Bad { + public function __toString() { + throw new Exception('Oops, I cannot do this'); + } +} + +$bad = new Bad(); +echo "$bad"; +--EXPECTF-- +Fatal error: Method Bad::__toString() must not throw an exception in %sbug60909_2.php on line 0 + + +!!!shutdown!!! diff --git a/Zend/tests/bug61767.phpt b/Zend/tests/bug61767.phpt new file mode 100644 index 0000000000..5270872e5d --- /dev/null +++ b/Zend/tests/bug61767.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #61767 (Shutdown functions not called in certain error situation) +--FILE-- +<?php +set_error_handler(function($code, $msg, $file = null, $line = null) { + echo "Error handler called ($msg)\n"; + throw new \ErrorException($msg, $code, 0, $file, $line); +}); + +register_shutdown_function(function(){ + echo "Shutting down\n"; + print_r(error_get_last()); +}); + +//$undefined = null; // defined variable does not cause problems +$undefined->foo(); +--EXPECTF-- +Error handler called (Undefined variable: undefined) + +Warning: Uncaught exception 'ErrorException' with message 'Undefined variable: undefined' in %sbug61767.php:13 +Stack trace: +#0 %sbug61767.php(13): {closure}(8, 'Undefined varia...', '%s', 13, Array) +#1 {main} + thrown in %sbug61767.php on line 13 + +Fatal error: Call to a member function foo() on a non-object in %sbug61767.php on line 13 +Shutting down +Array +( + [type] => 1 + [message] => Call to a member function foo() on a non-object + [file] => %sbug61767.php + [line] => 13 +) diff --git a/Zend/zend.c b/Zend/zend.c index 09338e7f83..9ab879a2a4 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -1028,6 +1028,29 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */ zend_stack context_stack; TSRMLS_FETCH(); + /* Report about uncaught exception in case of fatal errors */ + if (EG(exception)) { + switch (type) { + case E_CORE_ERROR: + case E_ERROR: + case E_RECOVERABLE_ERROR: + case E_PARSE: + case E_COMPILE_ERROR: + case E_USER_ERROR: + if (zend_is_executing(TSRMLS_C)) { + error_lineno = zend_get_executed_lineno(TSRMLS_C); + } + zend_exception_error(EG(exception), E_WARNING TSRMLS_CC); + EG(exception) = NULL; + if (zend_is_executing(TSRMLS_C) && EG(opline_ptr)) { + active_opline->lineno = error_lineno; + } + break; + default: + break; + } + } + /* Obtain relevant filename and lineno */ switch (type) { case E_CORE_ERROR: diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 60095f7062..d82493aeaf 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1490,6 +1490,7 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty if (retval) { zval_ptr_dtor(&retval); } + EG(exception) = NULL; zend_error_noreturn(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name); return FAILURE; } |