Skip to content

Commit 6408ebb

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #77627 method_exists on Closure::__invoke
2 parents 724230d + cfd4d3d commit 6408ebb

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
the method is private). (Nikita)
1212
. Implemented FR #77372 (Relative file path is removed from uploaded file).
1313
(Björn Tantau)
14+
15+
- Standard:
16+
. Fixed bug #77627 (method_exists on Closure::__invoke inconsistency).
17+
(krakjoe)
1418

1519
- Date:
1620
. Fixed bug #52480 (Incorrect difference using DateInterval) (Derick)

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
@@ -923,16 +923,22 @@ ZEND_FUNCTION(method_exists)
923923
func = Z_OBJ_HT_P(klass)->get_method(&obj, method_name, NULL);
924924
if (func != NULL) {
925925
if (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
926-
/* Returns true to the fake Closure's __invoke */
926+
/* Returns true for the fake Closure's __invoke */
927927
RETVAL_BOOL(func->common.scope == zend_ce_closure
928-
&& zend_string_equals_literal(method_name, ZEND_INVOKE_FUNC_NAME));
928+
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME));
929929

930930
zend_string_release_ex(func->common.function_name, 0);
931931
zend_free_trampoline(func);
932932
return;
933933
}
934934
RETURN_TRUE;
935935
}
936+
} else {
937+
/* Returns true for fake Closure::__invoke */
938+
if (ce == zend_ce_closure
939+
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME)) {
940+
RETURN_TRUE;
941+
}
936942
}
937943
RETURN_FALSE;
938944
}

0 commit comments

Comments
 (0)