1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

Fix #77627 method_exists on Closure::__invoke

This commit is contained in:
Joe Watkins
2021-05-22 11:06:45 +02:00
parent 8bcaaa3579
commit cfd4d3df0b
3 changed files with 25 additions and 2 deletions

2
NEWS
View File

@@ -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

15
Zend/tests/bug77627.phpt Normal file
View File

@@ -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)

View File

@@ -950,9 +950,9 @@ 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);
@@ -960,6 +960,12 @@ ZEND_FUNCTION(method_exists)
}
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;
}