$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";
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
bound: B (should be scoped to dummy class)
scoped to A: bool(true)
bound: B
-Done.
\ No newline at end of file
+Done.
--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();
echo "Done.\n";
--EXPECTF--
-Warning: Cannot bind an instance to a static closure in %s on line %d
Done.
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";
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)
}
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;
}
}
}