Skip to content

Commit cfd4d3d

Browse files
committed
Fix #77627 method_exists on Closure::__invoke
1 parent 8bcaaa3 commit cfd4d3d

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
- Standard:
99
. Fixed bug #81048 (phpinfo(INFO_VARIABLES) "Array to string conversion").
1010
(cmb)
11+
. Fixed bug #77627 (method_exists on Closure::__invoke inconsistency).
12+
(krakjoe)
1113

1214
03 Jun 2021, PHP 8.0.7
1315

Zend/tests/bug77627.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Fix for #77627 method_exists on Closure::__invoke without object returns false
3+
--FILE--
4+
<?php
5+
var_dump(method_exists(Closure::class, "__invoke"));
6+
var_dump(method_exists(Closure::class, "__INVOKE"));
7+
8+
$closure = function(){};
9+
10+
var_dump(method_exists($closure, "__INVOKE"));
11+
?>
12+
--EXPECT--
13+
bool(true)
14+
bool(true)
15+
bool(true)

Zend/zend_builtin_functions.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,16 +950,22 @@ ZEND_FUNCTION(method_exists)
950950
func = Z_OBJ_HT_P(klass)->get_method(&obj, method_name, NULL);
951951
if (func != NULL) {
952952
if (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
953-
/* Returns true to the fake Closure's __invoke */
953+
/* Returns true for the fake Closure's __invoke */
954954
RETVAL_BOOL(func->common.scope == zend_ce_closure
955-
&& zend_string_equals_literal(method_name, ZEND_INVOKE_FUNC_NAME));
955+
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME));
956956

957957
zend_string_release_ex(func->common.function_name, 0);
958958
zend_free_trampoline(func);
959959
return;
960960
}
961961
RETURN_TRUE;
962962
}
963+
} else {
964+
/* Returns true for fake Closure::__invoke */
965+
if (ce == zend_ce_closure
966+
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME)) {
967+
RETURN_TRUE;
968+
}
963969
}
964970
RETURN_FALSE;
965971
}

0 commit comments

Comments
 (0)