com php-src: Deprecate unbinding of $this of non-static methods: UPGRADING Zend/tests/closure_061.phpt Zend/zend_closures. c
| From: | Nikita Popov | Date: | Sat, 29 Sep 2018 19:01:27 +0000 |
| Subject: | com php-src: Deprecate unbinding of $this of non-static methods: UPGRADING Zend/tests/closure_061.phpt Zend/zend_closures. c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-103271@lists.php.net to get a copy of this message | ||
Commit: fc18f44213d59190a3e524e5c2f1a33f73be2cda
Author: Nikita Popov <nikita.ppv@gmail.com> Sat, 29 Sep 2018 20:58:17 +0200
Parents: c4cb3250cab9d793cd9efd1d00212a98e8aad4c3
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=fc18f44213d59190a3e524e5c2f1a33f73be2cda
Log:
Deprecate unbinding of $this of non-static methods
Static calls to non-static methods have been fully deprecated in
PHP 7.0 as part of https://wiki.php.net/rfc/reclassify_e_strict.
A combination of ReflectionMethod::getClosure() ("fake closures")
and Closure::bindTo() etc can be used to achieve the same behavior.
This commit ensures that a deprecation notice will be thrown also
in this case.
Changed paths:
M UPGRADING
M Zend/tests/closure_061.phpt
M Zend/zend_closures.c
Diff:
diff --git a/UPGRADING b/UPGRADING
index ccea43b..991c4bf 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -46,6 +46,12 @@ PHP 7.4 UPGRADE NOTES
4. Deprecated Functionality
========================================
+- Core:
+ . Unbinding $this of a non-static method through a combination of
+ ReflectionMethod::getClosure() and closure rebinding is deprecated. Doing
+ so is equivalent to calling a non-static method statically, which has been
+ deprecated since PHP 7.0.
+
========================================
5. Changed Functions
========================================
diff --git a/Zend/tests/closure_061.phpt b/Zend/tests/closure_061.phpt
index 1aa579a..f01e393 100644
--- a/Zend/tests/closure_061.phpt
+++ b/Zend/tests/closure_061.phpt
@@ -175,6 +175,8 @@ Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure
-------------------
bindTo(null, Cls::class):
+Unbinding $this of a method is deprecated
+
Success!
bindTo(new Cls, Cls::class):
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index 56808e2..6ee2325 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -82,10 +82,14 @@ static zend_bool zend_valid_closure_binding(
ZSTR_VAL(Z_OBJCE_P(newthis)->name));
return 0;
}
- } else if (!(func->common.fn_flags & ZEND_ACC_STATIC) && func->common.scope
- && func->type == ZEND_INTERNAL_FUNCTION) {
- zend_error(E_WARNING, "Cannot unbind $this of internal method");
- return 0;
+ } else if (is_fake_closure && func->common.scope
+ && !(func->common.fn_flags & ZEND_ACC_STATIC)) {
+ if (func->type == ZEND_INTERNAL_FUNCTION) {
+ zend_error(E_WARNING, "Cannot unbind $this of internal method");
+ return 0;
+ } else {
+ zend_error(E_DEPRECATED, "Unbinding $this of a method is deprecated");
+ }
}
if (scope && scope != func->common.scope && scope->type ==
ZEND_INTERNAL_CLASS) {