Skip to content

Commit 5c24f80

Browse files
committed
Promote "Cannot use parent" to fatal error
1 parent 0d55456 commit 5c24f80

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ PHP 8.0 UPGRADE NOTES
4545
. The default error_reporting level is now E_ALL. Previously it excluded
4646
E_NOTICE and E_DEPRECATED.
4747
. display_startup_errors is now enabled by default.
48+
. Using "parent" inside a class that has no parent will now result in a
49+
fatal compile-time error.
4850
. The @ operator will no longer silence fatal errors (E_ERROR, E_CORE_ERROR,
4951
E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR, E_PARSE). Error handlers
5052
that expect error_reporting to be 0 when @ is used, should be adjusted to

Zend/tests/class_name_as_scalar_error_002.phpt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,4 @@ namespace Foo\Bar {
1111
}
1212
?>
1313
--EXPECTF--
14-
Deprecated: Cannot use "parent" when current class scope has no parent in %s on line %d
15-
16-
Fatal error: Uncaught Error: Cannot use "parent" when current class scope has no parent in %s:%d
17-
Stack trace:
18-
#0 {main}
19-
thrown in %s on line %d
14+
Fatal error: Cannot use "parent" when current class scope has no parent in %s on line %d

Zend/tests/type_declarations/variance/parent_in_class_failure1.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ class B extends A {
1313

1414
?>
1515
--EXPECTF--
16-
Deprecated: Cannot use "parent" when current class scope has no parent in %s on line %d
17-
18-
Fatal error: Could not check compatibility between B::method(A $x) and A::method(parent $x), because class parent is not available in %s on line %d
16+
Fatal error: Cannot use "parent" when current class scope has no parent in %s on line %d

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
14081408
fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
14091409
fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
14101410
} else if (fetch_type == ZEND_FETCH_CLASS_PARENT && !ce->parent_name) {
1411-
zend_error(E_DEPRECATED,
1411+
zend_error_noreturn(E_COMPILE_ERROR,
14121412
"Cannot use \"parent\" when current class scope has no parent");
14131413
}
14141414
}

0 commit comments

Comments
 (0)