Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 6ba376f552238de643a665d355fd5e59c40315b5 2 parents a43c45e + b29dc14
Dmitry Stogov dstogov authored
4 NEWS
@@ -10,6 +10,10 @@ PHP NEWS
10 10 . Fixed bug #62955 (Only one directive is loaded from "Per Directory Values"
11 11 Windows registry). (aserbulov at parallels dot com)
12 12 . Fixed bug #62907 (Double free when use traits). (Dmitry)
  13 + . Fixed bug #61767 (Shutdown functions not called in certain error
  14 + situation). (Dmitry)
  15 + . Fixed bug #60909 (custom error handler throwing Exception + fatal error
  16 + = no shutdown function). (Dmitry)
13 17
14 18 - SOAP
15 19 . Fixed bug #50997 (SOAP Error when trying to submit 2nd Element of a choice).
6 Zend/tests/bug51394.phpt
@@ -13,4 +13,10 @@ function eh()
13 13 set_error_handler("eh");
14 14 $a = $empty($b);
15 15 --EXPECTF--
  16 +Warning: Uncaught exception 'Exception' with message 'error!' in %sbug51394.php:4
  17 +Stack trace:
  18 +#0 %sbug51394.php(9): eh(8, 'Undefined varia...', '%s', 9, Array)
  19 +#1 {main}
  20 + thrown in %sbug51394.php on line 4
  21 +
16 22 Fatal error: Function name must be a string in %sbug51394.php on line 9
24 Zend/tests/bug60909_1.phpt
... ... @@ -0,0 +1,24 @@
  1 +--TEST--
  2 +Bug #60909 (custom error handler throwing Exception + fatal error = no shutdown function).
  3 +--FILE--
  4 +<?php
  5 +register_shutdown_function(function(){echo("\n\n!!!shutdown!!!\n\n");});
  6 +set_error_handler(function($errno, $errstr, $errfile, $errline){
  7 + echo "error($errstr)";
  8 + throw new Exception("Foo");
  9 +});
  10 +
  11 +require 'notfound.php';
  12 +--EXPECTF--
  13 +error(require(notfound.php): failed to open stream: No such file or directory)
  14 +Warning: Uncaught exception 'Exception' with message 'Foo' in %sbug60909_1.php:5
  15 +Stack trace:
  16 +#0 %sbug60909_1.php(8): {closure}(2, 'require(notfoun...', '%s', 8, Array)
  17 +#1 %sbug60909_1.php(8): require()
  18 +#2 {main}
  19 + thrown in %sbug60909_1.php on line 5
  20 +
  21 +Fatal error: main(): Failed opening required 'notfound.php' (include_path='%s') in %sbug60909_1.php on line 8
  22 +
  23 +
  24 +!!!shutdown!!!
20 Zend/tests/bug60909_2.phpt
... ... @@ -0,0 +1,20 @@
  1 +--TEST--
  2 +Bug #60909 (custom error handler throwing Exception + fatal error = no shutdown function).
  3 +--FILE--
  4 +<?php
  5 +register_shutdown_function(function(){echo("\n\n!!!shutdown!!!\n\n");});
  6 +set_error_handler(function($errno, $errstr, $errfile, $errline){throw new Exception("Foo");});
  7 +
  8 +class Bad {
  9 + public function __toString() {
  10 + throw new Exception('Oops, I cannot do this');
  11 + }
  12 +}
  13 +
  14 +$bad = new Bad();
  15 +echo "$bad";
  16 +--EXPECTF--
  17 +Fatal error: Method Bad::__toString() must not throw an exception in %sbug60909_2.php on line 0
  18 +
  19 +
  20 +!!!shutdown!!!
34 Zend/tests/bug61767.phpt
... ... @@ -0,0 +1,34 @@
  1 +--TEST--
  2 +Bug #61767 (Shutdown functions not called in certain error situation)
  3 +--FILE--
  4 +<?php
  5 +set_error_handler(function($code, $msg, $file = null, $line = null) {
  6 + echo "Error handler called ($msg)\n";
  7 + throw new \ErrorException($msg, $code, 0, $file, $line);
  8 +});
  9 +
  10 +register_shutdown_function(function(){
  11 + echo "Shutting down\n";
  12 + print_r(error_get_last());
  13 +});
  14 +
  15 +//$undefined = null; // defined variable does not cause problems
  16 +$undefined->foo();
  17 +--EXPECTF--
  18 +Error handler called (Undefined variable: undefined)
  19 +
  20 +Warning: Uncaught exception 'ErrorException' with message 'Undefined variable: undefined' in %sbug61767.php:13
  21 +Stack trace:
  22 +#0 %sbug61767.php(13): {closure}(8, 'Undefined varia...', '%s', 13, Array)
  23 +#1 {main}
  24 + thrown in %sbug61767.php on line 13
  25 +
  26 +Fatal error: Call to a member function foo() on a non-object in %sbug61767.php on line 13
  27 +Shutting down
  28 +Array
  29 +(
  30 + [type] => 1
  31 + [message] => Call to a member function foo() on a non-object
  32 + [file] => %sbug61767.php
  33 + [line] => 13
  34 +)
23 Zend/zend.c
@@ -1028,6 +1028,29 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
1028 1028 zend_stack context_stack;
1029 1029 TSRMLS_FETCH();
1030 1030
  1031 + /* Report about uncaught exception in case of fatal errors */
  1032 + if (EG(exception)) {
  1033 + switch (type) {
  1034 + case E_CORE_ERROR:
  1035 + case E_ERROR:
  1036 + case E_RECOVERABLE_ERROR:
  1037 + case E_PARSE:
  1038 + case E_COMPILE_ERROR:
  1039 + case E_USER_ERROR:
  1040 + if (zend_is_executing(TSRMLS_C)) {
  1041 + error_lineno = zend_get_executed_lineno(TSRMLS_C);
  1042 + }
  1043 + zend_exception_error(EG(exception), E_WARNING TSRMLS_CC);
  1044 + EG(exception) = NULL;
  1045 + if (zend_is_executing(TSRMLS_C) && EG(opline_ptr)) {
  1046 + active_opline->lineno = error_lineno;
  1047 + }
  1048 + break;
  1049 + default:
  1050 + break;
  1051 + }
  1052 + }
  1053 +
1031 1054 /* Obtain relevant filename and lineno */
1032 1055 switch (type) {
1033 1056 case E_CORE_ERROR:
1  Zend/zend_object_handlers.c
@@ -1490,6 +1490,7 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
1490 1490 if (retval) {
1491 1491 zval_ptr_dtor(&retval);
1492 1492 }
  1493 + EG(exception) = NULL;
1493 1494 zend_error_noreturn(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name);
1494 1495 return FAILURE;
1495 1496 }

0 comments on commit 6ba376f

Please sign in to comment.
Something went wrong with that request. Please try again.