com php-src: Don't implicitly make closures in static methods static: Zend/tests/closure_041.phpt Zend/tests/closure_ 045.phpt
Zend/tests/closure_046.phpt Zend /zend_closures.c
| From: | Nikita Popov | Date: | Wed, 06 May 2015 15:29:05 +0000 |
| Subject: | com php-src: Don't implicitly make closures in static methods static: Zend/tests/closure_041.phpt Zend/tests/closure_ 045.phpt Zend/tests/closure_046.phpt Zend /zend_closures.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86629@lists.php.net to get a copy of this message | ||
Commit: bc2ff4a299a182c4ab9681fa6ba52cf747f53ace
Author: Nikita Popov <nikic@php.net> Wed, 6 May 2015 17:29:05 +0200
Parents: d1363e30fdd03431c7768aa2a4b7361bf07f42fd
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=bc2ff4a299a182c4ab9681fa6ba52cf747f53ace
Log:
Don't implicitly make closures in static methods static
It makes no sense that you can't write a closure using $this in a
static method, even though you can write one outside a class.
Now only closures that have been marked as static will be considered
to be static.
Fixes bug #65598.
Bugs:
https://bugs.php.net/65598
Changed paths:
M Zend/tests/closure_041.phpt
M Zend/tests/closure_045.phpt
M Zend/tests/closure_046.phpt
M Zend/zend_closures.c
Diff:
diff --git a/Zend/tests/closure_041.phpt b/Zend/tests/closure_041.phpt
index 79cf9f3..947517b 100644
--- a/Zend/tests/closure_041.phpt
+++ b/Zend/tests/closure_041.phpt
@@ -49,7 +49,7 @@ $d = $staticUnscoped->bindTo(null); $d(); echo "\n";
$d = $nonstaticUnscoped->bindTo(null); $d(); echo "\n";
$d = $staticScoped->bindTo(null); $d(); echo "\n";
$d = $nonstaticScoped->bindTo(null); $d(); echo "\n";
-//$d should have been turned to static
+// $d is still non-static
$d->bindTo($d);
echo "After binding, with same-class instance for the bound ones", "\n";
@@ -83,8 +83,6 @@ scoped to A: bool(true)
bound: no
scoped to A: bool(true)
bound: no
-
-Warning: Cannot bind an instance to a static closure in %s on line %d
After binding, with same-class instance for the bound ones
Warning: Cannot bind an instance to a static closure in %s on line %d
@@ -103,4 +101,4 @@ scoped to A: bool(false)
bound: B (should be scoped to dummy class)
scoped to A: bool(true)
bound: B
-Done.
\ No newline at end of file
+Done.
diff --git a/Zend/tests/closure_045.phpt b/Zend/tests/closure_045.phpt
index 4115691...c6276be 100644
--- a/Zend/tests/closure_045.phpt
+++ b/Zend/tests/closure_045.phpt
@@ -1,12 +1,12 @@
--TEST--
-Closure 045: Closures created in static methods are static, even without the keyword
+Closure 045: Closures created in static methods are not implicitly static
--FILE--
<?php
class A {
-static function foo() {
- return function () {};
-}
+ static function foo() {
+ return function () {};
+ }
}
$a = A::foo();
@@ -15,5 +15,4 @@ $a->bindTo(new A);
echo "Done.\n";
--EXPECTF--
-Warning: Cannot bind an instance to a static closure in %s on line %d
Done.
diff --git a/Zend/tests/closure_046.phpt b/Zend/tests/closure_046.phpt
index 30a9d3e..2985e6a 100644
--- a/Zend/tests/closure_046.phpt
+++ b/Zend/tests/closure_046.phpt
@@ -27,7 +27,7 @@ $nonstaticScoped(); echo "\n";
echo "After binding, no instance", "\n";
$d = $nonstaticUnscoped->bindTo(null, "static"); $d(); echo "\n";
$d = $nonstaticScoped->bindTo(null, "static"); $d(); echo "\n";
-//$d should have been turned to static
+// $d is still non-static
$d->bindTo($d);
echo "After binding, with same-class instance for the bound one", "\n";
@@ -54,8 +54,6 @@ bool(false)
bool(true)
bool(false)
-
-Warning: Cannot bind an instance to a static closure in %s on line %d
After binding, with same-class instance for the bound one
bool(false)
bool(true)
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index 97f0cbf..ec63f48 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -513,17 +513,14 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func,
zend_class_ent
}
ZVAL_UNDEF(&closure->this_ptr);
- /* Invariants:
- * If the closure is unscoped, it has no bound object.
- * The the closure is scoped, it's either static or it's bound */
+ /* Invariant:
+ * If the closure is unscoped or static, it has no bound object. */
closure->func.common.scope = scope;
closure->called_scope = called_scope;
if (scope) {
closure->func.common.fn_flags |= ZEND_ACC_PUBLIC;
if (this_ptr && Z_TYPE_P(this_ptr) == IS_OBJECT &&
(closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) {
ZVAL_COPY(&closure->this_ptr, this_ptr);
- } else {
- closure->func.common.fn_flags |= ZEND_ACC_STATIC;
}
}
}