summaryrefslogtreecommitdiff
path: root/Zend/zend_exceptions.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-09-24 15:24:51 +0200
committerNikita Popov <nikita.ppv@gmail.com>2018-06-16 12:41:03 +0200
commitd04917c7b361fd07e098fe29ae931fb6fac1d9e0 (patch)
treea37ad12b79f04abb6b6cf9efe9500da573eb00fd /Zend/zend_exceptions.c
parent0bd3fecbcbd37f63063155163f64e0591f4761ea (diff)
downloadphp-git-d04917c7b361fd07e098fe29ae931fb6fac1d9e0.tar.gz
Fixed bug #75218
I've introduced a new CompileError type, from which ParseError inherits. These errors are not parse errors in the narrow sense of the term, even though they happen to be generated during parsing in our implementation. Additionally reusing the ParseError class for this purpose would change existing error messages (if the exception is not caught) from a "Fatal error:" to a "Parse error:" prefix, and also the error kind from E_COMPILE_ERROR to E_PARSE.
Diffstat (limited to 'Zend/zend_exceptions.c')
-rw-r--r--Zend/zend_exceptions.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
index cbc0b8ed52..f0b2d5e824 100644
--- a/Zend/zend_exceptions.c
+++ b/Zend/zend_exceptions.c
@@ -34,6 +34,7 @@ ZEND_API zend_class_entry *zend_ce_throwable;
ZEND_API zend_class_entry *zend_ce_exception;
ZEND_API zend_class_entry *zend_ce_error_exception;
ZEND_API zend_class_entry *zend_ce_error;
+ZEND_API zend_class_entry *zend_ce_compile_error;
ZEND_API zend_class_entry *zend_ce_parse_error;
ZEND_API zend_class_entry *zend_ce_type_error;
ZEND_API zend_class_entry *zend_ce_argument_count_error;
@@ -154,7 +155,7 @@ ZEND_API ZEND_COLD void zend_throw_exception_internal(zval *exception) /* {{{ */
}
}
if (!EG(current_execute_data)) {
- if (exception && Z_OBJCE_P(exception) == zend_ce_parse_error) {
+ if (exception && (Z_OBJCE_P(exception) == zend_ce_parse_error || Z_OBJCE_P(exception) == zend_ce_compile_error)) {
return;
}
if(EG(exception)) {
@@ -221,7 +222,8 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type,
base_ce = i_get_exception_base(&obj);
- if (EXPECTED(class_type != zend_ce_parse_error || !(filename = zend_get_compiled_filename()))) {
+ if (EXPECTED((class_type != zend_ce_parse_error && class_type != zend_ce_compile_error)
+ || !(filename = zend_get_compiled_filename()))) {
ZVAL_STRING(&tmp, zend_get_executed_filename());
zend_update_property_ex(base_ce, &obj, ZSTR_KNOWN(ZEND_STR_FILE), &tmp);
zval_ptr_dtor(&tmp);
@@ -842,8 +844,12 @@ void zend_register_default_exception(void) /* {{{ */
zend_declare_property_null(zend_ce_error, "trace", sizeof("trace")-1, ZEND_ACC_PRIVATE);
zend_declare_property_null(zend_ce_error, "previous", sizeof("previous")-1, ZEND_ACC_PRIVATE);
+ INIT_CLASS_ENTRY(ce, "CompileError", NULL);
+ zend_ce_compile_error = zend_register_internal_class_ex(&ce, zend_ce_error);
+ zend_ce_compile_error->create_object = zend_default_exception_new;
+
INIT_CLASS_ENTRY(ce, "ParseError", NULL);
- zend_ce_parse_error = zend_register_internal_class_ex(&ce, zend_ce_error);
+ zend_ce_parse_error = zend_register_internal_class_ex(&ce, zend_ce_compile_error);
zend_ce_parse_error->create_object = zend_default_exception_new;
INIT_CLASS_ENTRY(ce, "TypeError", NULL);
@@ -963,12 +969,13 @@ ZEND_API ZEND_COLD void zend_exception_error(zend_object *ex, int severity) /* {
ZVAL_OBJ(&exception, ex);
ce_exception = Z_OBJCE(exception);
EG(exception) = NULL;
- if (ce_exception == zend_ce_parse_error) {
+ if (ce_exception == zend_ce_parse_error || ce_exception == zend_ce_compile_error) {
zend_string *message = zval_get_string(GET_PROPERTY(&exception, ZEND_STR_MESSAGE));
zend_string *file = zval_get_string(GET_PROPERTY_SILENT(&exception, ZEND_STR_FILE));
zend_long line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE));
- zend_error_helper(E_PARSE, ZSTR_VAL(file), line, "%s", ZSTR_VAL(message));
+ zend_error_helper(ce_exception == zend_ce_parse_error ? E_PARSE : E_COMPILE_ERROR,
+ ZSTR_VAL(file), line, "%s", ZSTR_VAL(message));
zend_string_release_ex(file, 0);
zend_string_release_ex(message, 0);