[php-src] PHP-8.6: Fix partial application treating methods named assert() as the global assert() (#25771)
| From: | Ho Hoang Phu via GitHub | Date: | Thu, 26 Nov 2026 16:31:30 +0000 |
| Subject: | [php-src] PHP-8.6: Fix partial application treating methods named assert() as the global assert() (#25771) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144229@lists.php.net to get a copy of this message | ||
Author: Ho Hoang Phu (hohphu8)
Committer: GitHub (web-flow)
Pusher: arnaud-lb
Date: 2026-11-26T17:31:26+01:00
Commit: https://github.com/php/php-src/commit/415e68cc0afe3c500049bf281fe54381dcc402dc
Raw diff: https://github.com/php/php-src/commit/415e68cc0afe3c500049bf281fe54381dcc402dc.diff
Fix partial application treating methods named assert() as the global assert() (#25771)
zp_compile_forwarding_call() checked function_name against ZEND_STR_ASSERT without checking
ZEND_INTERNAL_FUNCTION and common.scope == NULL, causing partial application on methods or user
functions named assert() to call global assert().
Changed paths:
A Zend/tests/partial_application/method_named_assert.phpt
M NEWS
M Zend/zend_partial.c
Diff:
diff --git a/NEWS b/NEWS
index 8222edce215f..aefa07c3c73f 100644
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,8 @@ PHP NEWS
. Fixed bug GH-25379 (array_map() foreach optimization changes callback
semantics). (prateekbhujel)
. Fix OSS-Fuzz #588264417. (ndossche)
+ . Fixed partial application treating methods named assert() as the global
+ assert(). (hohphu8)
- Curl:
. Fixed curl_reset() retaining CURLOPT_PRIVATE after reset. (lacatoire)
diff --git a/Zend/tests/partial_application/method_named_assert.phpt
b/Zend/tests/partial_application/method_named_assert.phpt
new file mode 100644
index 000000000000..f1682416e5c5
--- /dev/null
+++ b/Zend/tests/partial_application/method_named_assert.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Partial function application on methods named assert() must invoke the method, while real global
assert(?) keeps working
+--INI--
+zend.assertions=1
+assert.exception=1
+--FILE--
+<?php
+
+class Validator {
+ public function assert(bool $cond, string $label = 'default'): string {
+ return "INSTANCE:$label:" . ($cond ? 'true' : 'false');
+ }
+
+ public static function assertStatic(bool $cond): string {
+ return "CTRL:" . ($cond ? 'true' : 'false');
+ }
+}
+
+class StaticValidator {
+ public static function assert(bool $cond, string $label = 'static'): string {
+ return "STATIC:$label:" . ($cond ? 'true' : 'false');
+ }
+}
+
+$v = new Validator();
+$ctrl = $v->assertStatic(?);
+var_dump($ctrl(false));
+
+$p1 = $v->assert(?, 'inst');
+var_dump($p1(false));
+
+$p2 = StaticValidator::assert(?, 'cls');
+var_dump($p2(false));
+
+$p3 = $v->assert(...);
+var_dump($p3(false, 'fcc'));
+
+// Positive control: real global \assert(?) must still invoke global assert()
+$realAssert = \assert(?, 'real-assert-msg');
+var_dump($realAssert(true));
+try {
+ $realAssert(false);
+ echo "UNEXPECTED_PASS\n";
+} catch (AssertionError $e) {
+ echo "REAL_ASSERT_ERR:" . $e->getMessage() . "\n";
+}
+
+?>
+--EXPECT--
+string(10) "CTRL:false"
+string(19) "INSTANCE:inst:false"
+string(16) "STATIC:cls:false"
+string(18) "INSTANCE:fcc:false"
+bool(true)
+REAL_ASSERT_ERR:real-assert-msg
diff --git a/Zend/zend_partial.c b/Zend/zend_partial.c
index b227c1f9e257..5c980d76e4ab 100644
--- a/Zend/zend_partial.c
+++ b/Zend/zend_partial.c
@@ -522,8 +522,10 @@ static zend_ast *zp_compile_forwarding_call(
bool forward_superfluous_args,
zend_ast *stmts_ast, uint32_t const_args)
{
- bool is_assert = zend_string_equals(function->common.function_name,
- ZSTR_KNOWN(ZEND_STR_ASSERT));
+ bool is_assert = function->type == ZEND_INTERNAL_FUNCTION
+ && !function->common.scope
+ && zend_string_equals(function->common.function_name,
+ ZSTR_KNOWN(ZEND_STR_ASSERT));
zend_ast *args_ast = zend_ast_create_list(0, ZEND_AST_ARG_LIST);
zend_ast *call_ast = NULL;