From fc80305e48ac18f643c2ad7e549a3eb8e2454b17 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 23 Apr 2015 17:52:05 +0300 Subject: [PATCH] Cleanup comments and add related tests. --- Zend/tests/closure_058.phpt | 64 +++++++++++++++++++++++++++++++++++++ Zend/tests/closure_059.phpt | 38 ++++++++++++++++++++++ Zend/zend_closures.c | 5 ++- 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/closure_058.phpt create mode 100644 Zend/tests/closure_059.phpt diff --git a/Zend/tests/closure_058.phpt b/Zend/tests/closure_058.phpt new file mode 100644 index 0000000000..128661f4fc --- /dev/null +++ b/Zend/tests/closure_058.phpt @@ -0,0 +1,64 @@ +--TEST-- +Closure 058: Closure scope and object +--FILE-- +__invoke(); +$c = array($a,"__invoke"); +$c(); +call_user_func(array($a,"__invoke")); +$z(array($a,"__invoke")); + +echo "\n"; + +$x = new A(); +$b = $x->bar(); +$b(); +$b->__invoke(); +$c = array($b,"__invoke"); +$c(); +call_user_func(array($b,"__invoke")); +$z(array($b,"__invoke")); +--EXPECT-- +string(1) "A" +string(1) "A" +string(1) "A" +string(1) "A" +string(1) "A" +string(1) "A" +string(1) "A" +string(1) "A" +string(1) "A" +string(1) "A" + +string(1) "A" +string(1) "A" +object(A)#2 (0) { +} +string(1) "A" +string(1) "A" +object(A)#2 (0) { +} +string(1) "A" +string(1) "A" +object(A)#2 (0) { +} +string(1) "A" +string(1) "A" +object(A)#2 (0) { +} +string(1) "A" +string(1) "A" +object(A)#2 (0) { +} diff --git a/Zend/tests/closure_059.phpt b/Zend/tests/closure_059.phpt new file mode 100644 index 0000000000..de9c574746 --- /dev/null +++ b/Zend/tests/closure_059.phpt @@ -0,0 +1,38 @@ +--TEST-- +Closure 059: Closure type hinting +--FILE-- +__invoke($a); +call_user_func(array($f,"__invoke"), $a); + +try { + $f($b); +} catch (EngineException $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + $f->__invoke($b); +} catch (EngineException $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + call_user_func(array($f,"__invoke"), $b); +} catch (EngineException $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +--EXPECTF-- +Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s +Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s +Exception: Argument 1 passed to {closure}() must be an instance of A, instance of B %s diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index 843254c6ef..952e4ed1e0 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -184,7 +184,10 @@ ZEND_API zend_function *zend_get_closure_invoke_method(zend_object *object) /* { zend_function *invoke = (zend_function*)emalloc(sizeof(zend_function)); invoke->common = closure->func.common; - /* TODO: return ZEND_INTERNAL_FUNCTION, but arg_info representation is suitable for ZEND_USER_FUNCTION ??? */ + /* We return ZEND_INTERNAL_FUNCTION, but arg_info representation is the + * same as for ZEND_USER_FUNCTION (uses zend_string* instead of char*). + * This is not a problem, because ZEND_ACC_HAS_TYPE_HINTS is never set, + * and we won't check arguments on internal function */ invoke->type = ZEND_INTERNAL_FUNCTION; invoke->internal_function.fn_flags = ZEND_ACC_PUBLIC | ZEND_ACC_CALL_VIA_HANDLER | (closure->func.common.fn_flags & ZEND_ACC_RETURN_REFERENCE); invoke->internal_function.handler = ZEND_MN(Closure___invoke); -- 2.50.1