Skip to content

Commit deb44d4

Browse files
committed
Revert "Detect invalid uses of parent:: during compilation"
This reverts commit a9e6667. Breakage found in the wild: Mockery uses a parent:: call in the implementation regardless of whether the class has a parent or not: https://github.com/mockery/mockery/blob/4324afeaf9d95b492507e6587abb3f024e2576de/library/Mockery/Mock.php#L600 This change is not worth the compat break in 7.4.
1 parent a8c3e22 commit deb44d4

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

UPGRADING

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ PHP 7.4 UPGRADE NOTES
2222
========================================
2323

2424
- Core:
25-
. Referencing parent:: inside a class that does not have a parent will now
26-
generate a compile-time error. Previously the error was only emitted at
27-
run-time.
2825
. get_declared_classes() no longer returns anonymous classes that haven't
2926
been instantiated yet.
3027

Zend/tests/class_name_as_scalar_error_002.phpt

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

Zend/zend_compile.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,16 +1317,10 @@ static uint32_t zend_get_class_fetch_type_ast(zend_ast *name_ast) /* {{{ */
13171317

13181318
static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
13191319
{
1320-
if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && zend_is_scope_known()) {
1321-
zend_class_entry *ce = CG(active_class_entry);
1322-
if (!ce) {
1323-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
1324-
fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
1325-
fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
1326-
} else if (fetch_type == ZEND_FETCH_CLASS_PARENT && !ce->parent_name) {
1327-
zend_error_noreturn(E_COMPILE_ERROR,
1328-
"Cannot use \"parent\" when current class scope has no parent");
1329-
}
1320+
if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && !CG(active_class_entry) && zend_is_scope_known()) {
1321+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
1322+
fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
1323+
fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
13301324
}
13311325
}
13321326
/* }}} */

0 commit comments

Comments
 (0)