com php-src: Fixed bug #76980: NEWS Zend/tests/bug49908.phpt Zend/zend_execute_API.c

From: Date: Wed, 15 May 2019 10:46:23 +0000
Subject: com php-src: Fixed bug #76980: NEWS Zend/tests/bug49908.phpt Zend/zend_execute_API.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-106209@lists.php.net to get a copy of this message
Commit: 35353dc49a73a58c17c7896c4c4c3997ef2c007d Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 15 May 2019 12:46:23 +0200 Parents: 4fa32d67bf3fbea0241f0e786dbcb5517d25e1a2 Branches: PHP-7.2 PHP-7.3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=35353dc49a73a58c17c7896c4c4c3997ef2c007d Log: Fixed bug #76980 If we perform a class fetch that is not marked as exception safe, convert exceptions thrown by autoloaders into a fatal error. Ideally fetching the interfaces would be exception safe, but as it isn't right now, we must abort at this point. Bugs: https://bugs.php.net/76980 Changed paths: M NEWS M Zend/tests/bug49908.phpt M Zend/zend_execute_API.c Diff: diff --git a/NEWS b/NEWS index 46b7a99..eb52e52 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2019, PHP 7.2.20 +- Core: + . Fixed bug #76980 (Interface gets skipped if autoloader throws an exception). + (Nikita) 30 May 2019, PHP 7.2.19 diff --git a/Zend/tests/bug49908.phpt b/Zend/tests/bug49908.phpt index 2f33080..af8ab45 100644 --- a/Zend/tests/bug49908.phpt +++ b/Zend/tests/bug49908.phpt @@ -13,18 +13,22 @@ spl_autoload_register(function ($className) { } }); -new Foo; +try { + new Foo(); +} catch (Exception $e) { } + +// We never reach here. +var_dump(new Foo()); ?> --EXPECTF-- string(3) "Foo" string(3) "Bar" -Fatal error: Uncaught Exception: Bar in %s:%d +Fatal error: During class fetch: Uncaught Exception: Bar in %s:%d Stack trace: #0 [internal function]: {closure}('Bar') #1 %s(%d): spl_autoload_call('Bar') #2 [internal function]: {closure}('Foo') #3 %s(%d): spl_autoload_call('Foo') -#4 {main} - thrown in %s on line %d +#4 {main} in %s on line %d diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 9f10843..57ccf6c 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -1424,14 +1424,28 @@ zend_class_entry *zend_fetch_class_by_name(zend_string *class_name, const zval * if (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) { return zend_lookup_class_ex(class_name, key, 0); } else if ((ce = zend_lookup_class_ex(class_name, key, 1)) == NULL) { - if ((fetch_type & ZEND_FETCH_CLASS_SILENT) == 0 && !EG(exception)) { - if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) { - zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name)); - } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) { - zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name)); - } else { - zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name)); + if (fetch_type & ZEND_FETCH_CLASS_SILENT) { + return NULL; + } + if (EG(exception)) { + if (!(fetch_type & ZEND_FETCH_CLASS_EXCEPTION)) { + zend_string *exception_str; + zval exception_zv; + ZVAL_OBJ(&exception_zv, EG(exception)); + Z_ADDREF(exception_zv); + zend_clear_exception(); + exception_str = zval_get_string(&exception_zv); + zend_error_noreturn(E_ERROR, + "During class fetch: Uncaught %s", ZSTR_VAL(exception_str)); } + return NULL; + } + if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_INTERFACE) { + zend_throw_or_error(fetch_type, NULL, "Interface '%s' not found", ZSTR_VAL(class_name)); + } else if ((fetch_type & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_TRAIT) { + zend_throw_or_error(fetch_type, NULL, "Trait '%s' not found", ZSTR_VAL(class_name)); + } else { + zend_throw_or_error(fetch_type, NULL, "Class '%s' not found", ZSTR_VAL(class_name)); } return NULL; }

« previous php.cvs (#106209) next »