]> granicus.if.org Git - php/commitdiff
Improve previous fix
authorNikita Popov <nikic@php.net>
Fri, 9 Oct 2015 21:28:24 +0000 (23:28 +0200)
committerNikita Popov <nikic@php.net>
Fri, 9 Oct 2015 21:28:24 +0000 (23:28 +0200)
Don't forbid null binding on plain functions.

Zend/tests/bug70681.phpt
Zend/zend_closures.c

index a99180b0ce553889c14f7de0815afbc4f1aea2d8..9dd09b07b8d16b12c416ad888f4f73e8d6639456 100644 (file)
@@ -6,6 +6,11 @@ Bug #70681: Segfault when binding $this of internal instance method to null
 $c = (new ReflectionMethod('SplStack', 'count'))->getClosure(new SplStack);
 $c = $c->bindTo(null);
 
+$c = (new ReflectionFunction('strlen'))->getClosure();
+$c = $c->bindTo(null);
+var_dump($c("foo"));
+
 ?>
 --EXPECTF--
 Warning: Cannot unbind $this of internal method in %s on line %d
+int(3)
index 772eb12ecc002fc38c62b642342e102ed224670b..582a1f77841f11174d37a5c1d7cd5d956f1dd6a6 100644 (file)
@@ -89,7 +89,7 @@ ZEND_METHOD(Closure, bind)
        }
 
        if (newthis == NULL && !(closure->func.common.fn_flags & ZEND_ACC_STATIC)
-                       && closure->func.type == ZEND_INTERNAL_FUNCTION) {
+                       && closure->func.common.scope && closure->func.type == ZEND_INTERNAL_FUNCTION) {
                zend_error(E_WARNING, "Cannot unbind $this of internal method");
                return;
        }