Skip to content

Request #75765 Throw exception instead of a fatal error when extends/implements #3010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Zend/tests/bug30519.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ class test implements a {
}
?>
--EXPECTF--
Fatal error: Interface 'a' not found in %sbug30519.php on line 2
Fatal error: Uncaught Error: Interface 'a' not found in %sbug30519.php:2
Stack trace:
#0 {main}
thrown in %sbug30519.php on line 2

2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6370,7 +6370,7 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */
"Cannot use '%s' as class name as it is reserved", ZSTR_VAL(extends_name));
}

zend_compile_class_ref(&extends_node, extends_ast, 0);
zend_compile_class_ref(&extends_node, extends_ast, 1);
ce->ce_flags |= ZEND_ACC_INHERITED;
}

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -6934,7 +6934,7 @@ ZEND_VM_HANDLER(144, ZEND_ADD_INTERFACE, ANY, CONST)
SAVE_OPLINE();
iface = CACHED_PTR(Z_CACHE_SLOT_P(RT_CONSTANT(opline, opline->op2)));
if (UNEXPECTED(iface == NULL)) {
iface = zend_fetch_class_by_name(Z_STR_P(RT_CONSTANT(opline, opline->op2)), RT_CONSTANT(opline, opline->op2) + 1, ZEND_FETCH_CLASS_INTERFACE);
iface = zend_fetch_class_by_name(Z_STR_P(RT_CONSTANT(opline, opline->op2)), RT_CONSTANT(opline, opline->op2) + 1, ZEND_FETCH_CLASS_INTERFACE | ZEND_FETCH_CLASS_EXCEPTION);
if (UNEXPECTED(iface == NULL)) {
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_ADD_INTERFACE_SPEC_CONST_HANDL
SAVE_OPLINE();
iface = CACHED_PTR(Z_CACHE_SLOT_P(RT_CONSTANT(opline, opline->op2)));
if (UNEXPECTED(iface == NULL)) {
iface = zend_fetch_class_by_name(Z_STR_P(RT_CONSTANT(opline, opline->op2)), RT_CONSTANT(opline, opline->op2) + 1, ZEND_FETCH_CLASS_INTERFACE);
iface = zend_fetch_class_by_name(Z_STR_P(RT_CONSTANT(opline, opline->op2)), RT_CONSTANT(opline, opline->op2) + 1, ZEND_FETCH_CLASS_INTERFACE | ZEND_FETCH_CLASS_EXCEPTION);
if (UNEXPECTED(iface == NULL)) {
ZEND_VM_NEXT_OPCODE_CHECK_EXCEPTION();
}
Expand Down
13 changes: 12 additions & 1 deletion ext/spl/tests/bug73423.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@ foreach (new \RecursiveIteratorIterator (new fooIterator ($foo)) as $bar) ;

?>
--EXPECTF--
Fatal error: Class 'NotExists' not found in %sbug73423.php(%d) : eval()'d code on line 1
Fatal error: Uncaught Error: Class 'NotExists' not found in %sbug73423.php(%d) : eval()'d code:1
Stack trace:
#0 %sbug73423.php(%d): eval()
#1 %sbug73423.php(%d): fooIterator->__destruct()
#2 {main}

Next Error: Class 'NotExists' not found in %sbug73423.php(%d) : eval()'d code:1
Stack trace:
#0 %sbug73423.php(%d): eval()
#1 %sbug73423.php(%d): fooIterator->__destruct()
#2 {main}
thrown in %sbug73423.php(%d) : eval()'d code on line 1
5 changes: 4 additions & 1 deletion tests/classes/autoload_010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ class C implements UndefI
--EXPECTF--
In autoload: string(6) "UndefI"

Fatal error: Interface 'UndefI' not found in %s on line %d
Fatal error: Uncaught Error: Interface 'UndefI' not found in %s:%d
Stack trace:
#0 {main}
thrown in %sautoload_010.php on line %d
5 changes: 4 additions & 1 deletion tests/classes/autoload_011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ class C extends UndefBase
--EXPECTF--
In autoload: string(9) "UndefBase"

Fatal error: Class 'UndefBase' not found in %s on line %d
Fatal error: Uncaught Error: Class 'UndefBase' not found in %s:%d
Stack trace:
#0 {main}
thrown in %sautoload_011.php on line %d
23 changes: 23 additions & 0 deletions tests/classes/bug75765.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Ensure undefined class extending throws the exception.
--FILE--
<?php
try {
class C extends UndefinedClass
{
}
} catch (Error $e) {
var_dump($e->getMessage());
}

try {
class C implements UndefinedInterface
{
}
} catch (Error $e) {
var_dump($e->getMessage());
}
?>
--EXPECT--
string(32) "Class 'UndefinedClass' not found"
string(40) "Interface 'UndefinedInterface' not found"