Skip to content

Commit

Permalink
Fix #77627 method_exists on Closure::__invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
krakjoe committed May 25, 2021
1 parent 8bcaaa3 commit cfd4d3d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ PHP NEWS
- Standard:
. Fixed bug #81048 (phpinfo(INFO_VARIABLES) "Array to string conversion").
(cmb)
. Fixed bug #77627 (method_exists on Closure::__invoke inconsistency).
(krakjoe)

03 Jun 2021, PHP 8.0.7

Expand Down
15 changes: 15 additions & 0 deletions Zend/tests/bug77627.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Fix for #77627 method_exists on Closure::__invoke without object returns false
--FILE--
<?php
var_dump(method_exists(Closure::class, "__invoke"));
var_dump(method_exists(Closure::class, "__INVOKE"));

$closure = function(){};

var_dump(method_exists($closure, "__INVOKE"));
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
10 changes: 8 additions & 2 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,16 +950,22 @@ ZEND_FUNCTION(method_exists)
func = Z_OBJ_HT_P(klass)->get_method(&obj, method_name, NULL);
if (func != NULL) {
if (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) {
/* Returns true to the fake Closure's __invoke */
/* Returns true for the fake Closure's __invoke */
RETVAL_BOOL(func->common.scope == zend_ce_closure
&& zend_string_equals_literal(method_name, ZEND_INVOKE_FUNC_NAME));
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME));

zend_string_release_ex(func->common.function_name, 0);
zend_free_trampoline(func);
return;
}
RETURN_TRUE;
}
} else {
/* Returns true for fake Closure::__invoke */
if (ce == zend_ce_closure
&& zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME)) {
RETURN_TRUE;
}
}
RETURN_FALSE;
}
Expand Down

0 comments on commit cfd4d3d

Please sign in to comment.