Skip to content

Commit f0c9265

Browse files
committed
Fix bug #65322: compile time errors won't trigger auto loading
Also fixes duplicate bugs #54054 and #42098. Furthermore this fixes incorrect error messages thrown from code running inside an error handler when a compilation is in progress. The error file and line are now correctly associated with the file/line of the executor, rather than the compiler.
1 parent d143c2b commit f0c9265

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2013, PHP 5.4.21
44

5+
- Core:
6+
. Fixed bug #65322 (compile time errors won't trigger auto loading). (Nikita)
7+
58
- CLI server:
69
. Fixed bug #65633 (built-in server treat some http headers as
710
case-sensitive). (Adam)

Zend/tests/bug65322.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #65322: compile time errors won't trigger auto loading
3+
--FILE--
4+
<?php
5+
6+
spl_autoload_register(function($class) {
7+
var_dump($class);
8+
class B {}
9+
});
10+
11+
set_error_handler(function($_, $msg, $file) {
12+
var_dump($msg, $file);
13+
new B;
14+
});
15+
16+
eval('class A { function a() {} function __construct() {} }');
17+
18+
?>
19+
--EXPECTF--
20+
string(50) "Redefining already defined constructor for class A"
21+
string(%d) "%s(%d) : eval()'d code"
22+
string(1) "B"

Zend/tests/errmsg_045.phpt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Error message in error handler during compilation
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function($_, $msg, $file) {
7+
var_dump($msg, $file);
8+
echo $undefined;
9+
});
10+
11+
eval('class A { function a() {} function __construct() {} }');
12+
13+
?>
14+
--EXPECTF--
15+
string(50) "Redefining already defined constructor for class A"
16+
string(%d) "%s(%d) : eval()'d code"
17+
18+
Notice: Undefined variable: undefined in %s on line %d

Zend/zend.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
11831183
* such scripts recursivly, but some CG() variables may be
11841184
* inconsistent. */
11851185

1186-
in_compilation = zend_is_compiling(TSRMLS_C);
1186+
in_compilation = CG(in_compilation);
11871187
if (in_compilation) {
11881188
saved_class_entry = CG(active_class_entry);
11891189
CG(active_class_entry) = NULL;
@@ -1195,6 +1195,7 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
11951195
SAVE_STACK(declare_stack);
11961196
SAVE_STACK(list_stack);
11971197
SAVE_STACK(context_stack);
1198+
CG(in_compilation) = 0;
11981199
}
11991200

12001201
if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC) == SUCCESS) {
@@ -1219,6 +1220,7 @@ ZEND_API void zend_error(int type, const char *format, ...) /* {{{ */
12191220
RESTORE_STACK(declare_stack);
12201221
RESTORE_STACK(list_stack);
12211222
RESTORE_STACK(context_stack);
1223+
CG(in_compilation) = 1;
12221224
}
12231225

12241226
if (!EG(user_error_handler)) {

0 commit comments

Comments
 (0)