]> granicus.if.org Git - php/commitdiff
Closure::fromCallable(): Getting non-static method statically
authorNikita Popov <nikic@php.net>
Tue, 5 Jul 2016 13:51:11 +0000 (15:51 +0200)
committerNikita Popov <nikic@php.net>
Tue, 5 Jul 2016 13:52:03 +0000 (15:52 +0200)
As this is new functionality, I'm going directly for a TypeError,
rather than a deprecation warning.

Zend/tests/closures/closure_from_callable_non_static_statically.phpt [new file with mode: 0644]
Zend/zend_closures.c

diff --git a/Zend/tests/closures/closure_from_callable_non_static_statically.phpt b/Zend/tests/closures/closure_from_callable_non_static_statically.phpt
new file mode 100644 (file)
index 0000000..17d39c0
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+Testing Closure::fromCallable() functionality: Getting non-static method statically
+--FILE--
+<?php
+
+class A {
+    public function method() {
+    }
+}
+
+try {
+    $fn = Closure::fromCallable(['A', 'method']);
+    $fn();
+} catch (TypeError $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Failed to create closure from callable: non-static method A::method() should not be called statically
index 137e437fb945f9d6e255965f07633416d566d30c..bedf022a4b416346c9b8db5bfc218c940da3821c 100644 (file)
@@ -322,7 +322,7 @@ ZEND_METHOD(Closure, fromCallable)
        success = zend_create_closure_from_callable(return_value, callable, &error);
        EG(current_execute_data) = execute_data;
 
-       if (success == FAILURE) {
+       if (success == FAILURE || error) {
                if (error) {
                        zend_throw_exception_ex(zend_ce_type_error, 0, "Failed to create closure from callable: %s", error);
                        efree(error);