com php-src: Closure::fromCallable(): Getting non-static method statically: Zend/tests/closures/closure_from_callable_non_static_ statically.phpt
Zend/zend_closures.c
| From: | Nikita Popov | Date: | Tue, 05 Jul 2016 13:52:03 +0000 |
| Subject: | com php-src: Closure::fromCallable(): Getting non-static method statically: Zend/tests/closures/closure_from_callable_non_static_ statically.phpt Zend/zend_closures.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92804@lists.php.net to get a copy of this message | ||
Commit: dbe6a231942ff4cbd2f6373828cecf4744356886
Author: Nikita Popov <nikic@php.net> Tue, 5 Jul 2016 15:51:11 +0200
Parents: ceae9fb54013d1fac0bf7987398501915b054209
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dbe6a231942ff4cbd2f6373828cecf4744356886
Log:
Closure::fromCallable(): Getting non-static method statically
As this is new functionality, I'm going directly for a TypeError,
rather than a deprecation warning.
Changed paths:
A Zend/tests/closures/closure_from_callable_non_static_statically.phpt
M Zend/zend_closures.c
Diff:
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
index 0000000..17d39c0
--- /dev/null
+++ b/Zend/tests/closures/closure_from_callable_non_static_statically.phpt
@@ -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
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index 137e437..bedf022 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -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);