Skip to content

Commit 6ba376f

Browse files
committed
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
2 parents a43c45e + b29dc14 commit 6ba376f

File tree

7 files changed

+112
-0
lines changed

7 files changed

+112
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug #62955 (Only one directive is loaded from "Per Directory Values"
1111
Windows registry). (aserbulov at parallels dot com)
1212
. 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)
1317

1418
- SOAP
1519
. Fixed bug #50997 (SOAP Error when trying to submit 2nd Element of a choice).

Zend/tests/bug51394.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ function eh()
1313
set_error_handler("eh");
1414
$a = $empty($b);
1515
--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+
1622
Fatal error: Function name must be a string in %sbug51394.php on line 9

Zend/tests/bug60909_1.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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!!!

Zend/tests/bug60909_2.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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!!!

Zend/tests/bug61767.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)

Zend/zend.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,29 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
10281028
zend_stack context_stack;
10291029
TSRMLS_FETCH();
10301030

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+
10311054
/* Obtain relevant filename and lineno */
10321055
switch (type) {
10331056
case E_CORE_ERROR:

Zend/zend_object_handlers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ ZEND_API int zend_std_cast_object_tostring(zval *readobj, zval *writeobj, int ty
14901490
if (retval) {
14911491
zval_ptr_dtor(&retval);
14921492
}
1493+
EG(exception) = NULL;
14931494
zend_error_noreturn(E_ERROR, "Method %s::__toString() must not throw an exception", ce->name);
14941495
return FAILURE;
14951496
}

0 commit comments

Comments
 (0)