mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Make missing trait error recoverable
We were already handling NULL as a case, but seem to have forgotten to pass the ZEND_FETCH_CLASS_EXCEPTION flag. Also make "is not a trait" error recoverable, there's no reason why it can't be. Fixes GH-17959 Closes GH-17960
This commit is contained in:
parent
0a811cea4f
commit
8731c95b35
9 changed files with 46 additions and 8 deletions
2
NEWS
2
NEWS
|
@ -27,6 +27,8 @@ PHP NEWS
|
|||
. Fixed bug GH-17442 (Engine UAF with reference assign and dtor). (nielsdos)
|
||||
. Improved error message of UnhandledMatchError for
|
||||
zend.exception_string_param_max_len=0. (timwolla)
|
||||
. Fixed bug GH-17959 (Relax missing trait fatal error to error exception).
|
||||
(ilutov)
|
||||
|
||||
- Curl:
|
||||
. Added curl_multi_get_handles(). (timwolla)
|
||||
|
|
|
@ -12,4 +12,7 @@ $test = new TraitsTest();
|
|||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Trait "THello" not found in %s on line %d
|
||||
Fatal error: Uncaught Error: Trait "THello" not found in %s:%d
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in %s on line %d
|
||||
|
|
|
@ -9,4 +9,7 @@ class A {
|
|||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: Trait "abc" not found in %s on line %d
|
||||
Fatal error: Uncaught Error: Trait "abc" not found in %s:%d
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in %s on line %d
|
||||
|
|
|
@ -12,4 +12,7 @@ class A {
|
|||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: A cannot use abc - it is not a trait in %s on line %d
|
||||
Fatal error: Uncaught Error: A cannot use abc - it is not a trait in %s:%d
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in %s on line %d
|
||||
|
|
|
@ -12,4 +12,7 @@ class A {
|
|||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: A cannot use abc - it is not a trait in %s on line %d
|
||||
Fatal error: Uncaught Error: A cannot use abc - it is not a trait in %s:%d
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in %s on line %d
|
||||
|
|
|
@ -12,4 +12,7 @@ class A {
|
|||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: A cannot use abc - it is not a trait in %s on line %d
|
||||
Fatal error: Uncaught Error: A cannot use abc - it is not a trait in %s:%d
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in %s on line %d
|
||||
|
|
|
@ -12,4 +12,7 @@ class A {
|
|||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Fatal error: A cannot use abc - it is not a trait in %s on line %d
|
||||
Fatal error: Uncaught Error: A cannot use abc - it is not a trait in %s:%d
|
||||
Stack trace:
|
||||
#0 {main}
|
||||
thrown in %s on line %d
|
||||
|
|
18
Zend/tests/traits/gh17959.phpt
Normal file
18
Zend/tests/traits/gh17959.phpt
Normal file
|
@ -0,0 +1,18 @@
|
|||
--TEST--
|
||||
GH-17959: Missing trait error is recoverable
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
try {
|
||||
class C {
|
||||
use MissingTrait;
|
||||
}
|
||||
} catch (Error $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECT--
|
||||
Error: Trait "MissingTrait" not found
|
||||
===DONE===
|
|
@ -3546,13 +3546,13 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
|
|||
|
||||
for (i = 0; i < ce->num_traits; i++) {
|
||||
zend_class_entry *trait = zend_fetch_class_by_name(ce->trait_names[i].name,
|
||||
ce->trait_names[i].lc_name, ZEND_FETCH_CLASS_TRAIT);
|
||||
ce->trait_names[i].lc_name, ZEND_FETCH_CLASS_TRAIT | ZEND_FETCH_CLASS_EXCEPTION);
|
||||
if (UNEXPECTED(trait == NULL)) {
|
||||
free_alloca(traits_and_interfaces, use_heap);
|
||||
return NULL;
|
||||
}
|
||||
if (UNEXPECTED(!(trait->ce_flags & ZEND_ACC_TRAIT))) {
|
||||
zend_error_noreturn(E_ERROR, "%s cannot use %s - it is not a trait", ZSTR_VAL(ce->name), ZSTR_VAL(trait->name));
|
||||
zend_throw_error(NULL, "%s cannot use %s - it is not a trait", ZSTR_VAL(ce->name), ZSTR_VAL(trait->name));
|
||||
free_alloca(traits_and_interfaces, use_heap);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue