From cfd4d3df0bf6397b80108f6e2d144afbb55e0763 Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Sat, 22 May 2021 11:06:45 +0200 Subject: [PATCH] Fix #77627 method_exists on Closure::__invoke --- NEWS | 2 ++ Zend/tests/bug77627.phpt | 15 +++++++++++++++ Zend/zend_builtin_functions.c | 10 ++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/bug77627.phpt diff --git a/NEWS b/NEWS index 845382bb53c..1e97f1dd876 100644 --- a/NEWS +++ b/NEWS @@ -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 diff --git a/Zend/tests/bug77627.phpt b/Zend/tests/bug77627.phpt new file mode 100644 index 00000000000..a67a8c2fad7 --- /dev/null +++ b/Zend/tests/bug77627.phpt @@ -0,0 +1,15 @@ +--TEST-- +Fix for #77627 method_exists on Closure::__invoke without object returns false +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 5ec365c9205..eea925feee4 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -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; }