Skip to content

Commit a112ec1

Browse files
committed
tests
1 parent 5c4c79e commit a112ec1

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

Zend/tests/first_class_callable_004.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ First Class Callable from Private Scope
44
<?php
55
class Foo {
66
private function method() {
7-
return "OK";
7+
return __METHOD__;
88
}
99

1010
public function bar() {
@@ -18,4 +18,4 @@ $bar = $foo->bar(...);
1818
echo ($bar())();
1919
?>
2020
--EXPECT--
21-
OK
21+
Foo::method
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
First Class Callable from NEW
3+
--FILE--
4+
<?php
5+
class Foo {
6+
7+
}
8+
9+
new Foo(...);
10+
?>
11+
--EXPECTF--
12+
Fatal error: cannot create Closure from call to constructor in %s on line 6
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
First Class Callable from Closure::__invoke
3+
--FILE--
4+
<?php
5+
$closure = function() {
6+
return "OK";
7+
};
8+
9+
$foo = $closure->__invoke(...);
10+
11+
echo $foo();
12+
?>
13+
--EXPECT--
14+
OK

Zend/zend_closures.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,13 @@ void zend_closure_from_frame(zval *return_value, zend_execute_data *call) { /* {
745745
}
746746

747747
if (mptr->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
748+
if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_THIS && Z_OBJCE(call->This) == zend_ce_closure
749+
&& zend_string_equals_literal(mptr->common.function_name, "__invoke")) {
750+
zend_free_trampoline(mptr);
751+
RETURN_OBJ_COPY(Z_OBJ(call->This));
752+
}
753+
754+
748755
memset(&trampoline, 0, sizeof(zend_internal_function));
749756
trampoline.type = ZEND_INTERNAL_FUNCTION;
750757
trampoline.fn_flags = mptr->common.fn_flags & ZEND_ACC_STATIC;

0 commit comments

Comments
 (0)