Skip to content
Permalink
Browse files

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.
  • Loading branch information...
nikic committed Mar 4, 2019
1 parent a8c3e22 commit deb44d405eb27a6654ad9a57c1e5f641218b22a4
Showing with 8 additions and 14 deletions.
  1. +0 −3 UPGRADING
  2. +4 −1 Zend/tests/class_name_as_scalar_error_002.phpt
  3. +4 −10 Zend/zend_compile.c
@@ -22,9 +22,6 @@ PHP 7.4 UPGRADE NOTES
========================================

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

@@ -11,4 +11,7 @@ namespace Foo\Bar {
}
?>
--EXPECTF--
Fatal error: Cannot use "parent" when current class scope has no parent in %s on line %d
Fatal error: Uncaught Error: Cannot use "parent" when current class scope has no parent in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
@@ -1317,16 +1317,10 @@ static uint32_t zend_get_class_fetch_type_ast(zend_ast *name_ast) /* {{{ */

static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
{
if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && zend_is_scope_known()) {
zend_class_entry *ce = CG(active_class_entry);
if (!ce) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
} else if (fetch_type == ZEND_FETCH_CLASS_PARENT && !ce->parent_name) {
zend_error_noreturn(E_COMPILE_ERROR,
"Cannot use \"parent\" when current class scope has no parent");
}
if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && !CG(active_class_entry) && zend_is_scope_known()) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
}
}
/* }}} */

0 comments on commit deb44d4

Please sign in to comment.
You can’t perform that action at this time.