com php-src: Revert "Detect invalid uses of parent:: during compilation": UPGRADING Zend/tests/class_name_as_scalar_error_0 02.phpt
Zend/zend_compile.c
| From: | Nikita Popov | Date: | Mon, 04 Mar 2019 11:24:02 +0000 |
| Subject: | com php-src: Revert "Detect invalid uses of parent:: during compilation": UPGRADING Zend/tests/class_name_as_scalar_error_0 02.phpt Zend/zend_compile.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104984@lists.php.net to get a copy of this message | ||
Commit: deb44d405eb27a6654ad9a57c1e5f641218b22a4
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 4 Mar 2019 12:18:33 +0100
Parents: a8c3e22d231a9993c253d446ce23425662ac1645
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=deb44d405eb27a6654ad9a57c1e5f641218b22a4
Log:
Revert "Detect invalid uses of parent:: during compilation"
This reverts commit a9e6667817c38f22f4645ec5b4e5c6b0e4b928fa.
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.
Changed paths:
M UPGRADING
M Zend/tests/class_name_as_scalar_error_002.phpt
M Zend/zend_compile.c
Diff:
diff --git a/UPGRADING b/UPGRADING
index 888ae8f..e20a9e2 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -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.
diff --git a/Zend/tests/class_name_as_scalar_error_002.phpt
b/Zend/tests/class_name_as_scalar_error_002.phpt
index ebb2dd4..3abba7f 100644
--- a/Zend/tests/class_name_as_scalar_error_002.phpt
+++ b/Zend/tests/class_name_as_scalar_error_002.phpt
@@ -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
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 9bf70d8..bb27b6e 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -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");
}
}
/* }}} */