mirror of
https://github.com/php/php-src.git
synced 2026-03-24 16:22:37 +01:00
Fixed bug #35634 (Erroneous "Class declarations may not be nested" error raised). (Carl P. Corliss)
This commit is contained in:
36
Zend/tests/bug35634.phpt
Executable file
36
Zend/tests/bug35634.phpt
Executable file
@@ -0,0 +1,36 @@
|
||||
--TEST--
|
||||
Bug #35634 (Erroneous "Class declarations may not be nested" error raised)
|
||||
--INI--
|
||||
error_reporting=0
|
||||
--FILE--
|
||||
<?php
|
||||
if (defined("pass3")) {
|
||||
|
||||
class ErrorClass {
|
||||
}
|
||||
|
||||
} else if (defined("pass2")) {
|
||||
|
||||
class TestClass {
|
||||
function __construct() {
|
||||
}
|
||||
function TestClass() {
|
||||
$this->__construct();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
function errorHandler($errorNumber, $errorMessage, $fileName, $lineNumber) {
|
||||
define("pass3", 1);
|
||||
include(__FILE__);
|
||||
die("Error: $errorMessage ($fileName:$lineNumber)\n");
|
||||
}
|
||||
|
||||
set_error_handler('errorHandler');
|
||||
define("pass2", 1);
|
||||
include(__FILE__);
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Error: Redefining already defined constructor for class TestClass (%sbug35634.php:12)
|
||||
17
Zend/zend.c
17
Zend/zend.c
@@ -1391,6 +1391,8 @@ ZEND_API void zend_error(int type, const char *format, ...)
|
||||
char *error_filename;
|
||||
uint error_lineno;
|
||||
zval *orig_user_error_handler;
|
||||
zend_bool in_compilation;
|
||||
zend_class_entry *saved_class_entry;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
/* Obtain relevant filename and lineno */
|
||||
@@ -1504,6 +1506,17 @@ ZEND_API void zend_error(int type, const char *format, ...)
|
||||
orig_user_error_handler = EG(user_error_handler);
|
||||
EG(user_error_handler) = NULL;
|
||||
|
||||
/* User error handler may include() additinal PHP files.
|
||||
* If an error was generated during comilation PHP will compile
|
||||
* such scripts recursivly, but some CG() variables may be
|
||||
* inconsistent. */
|
||||
|
||||
in_compilation = zend_is_compiling(TSRMLS_C);
|
||||
if (in_compilation) {
|
||||
saved_class_entry = CG(active_class_entry);
|
||||
CG(active_class_entry) = NULL;
|
||||
}
|
||||
|
||||
if (call_user_function_ex(CG(function_table), NULL, orig_user_error_handler, &retval, 5, params, 1, NULL TSRMLS_CC)==SUCCESS) {
|
||||
if (retval) {
|
||||
if (Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval) == 0) {
|
||||
@@ -1516,6 +1529,10 @@ ZEND_API void zend_error(int type, const char *format, ...)
|
||||
zend_error_cb(type, error_filename, error_lineno, format, args);
|
||||
}
|
||||
|
||||
if (in_compilation) {
|
||||
CG(active_class_entry) = saved_class_entry;
|
||||
}
|
||||
|
||||
if (!EG(user_error_handler)) {
|
||||
EG(user_error_handler) = orig_user_error_handler;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user