[php-src] master: Merge branch 'PHP-8.5'

Weilin Du <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Weilin Du (LamentXU123)
Date: 2026-08-12T22:28:10+08:00

Commit: https://github.com/php/php-src/commit/7e130da928c839541f4b8ffb25631f395404ba22
Raw diff: https://github.com/php/php-src/commit/7e130da928c839541f4b8ffb25631f395404ba22.diff

Merge branch 'PHP-8.5'

* PHP-8.5:
  ext/readline: Fix class constant completion in readline interactive shell (#23218)

Changed paths:
  A  ext/readline/tests/readline_cli_completion_class_constant.phpt
  M  NEWS
  M  ext/readline/readline_cli.c


Diff:

diff --git a/NEWS b/NEWS
index fa2bc69c39f7..3a5f08491611 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ PHP                                                                        NEWS
     left busy for the next fetch, and rows delivered from a result another
     statement took over. (KentarouTakeda)
 
+- Readline:
+  . Fixed class constant completion in the interactive shell. (Weilin Du)
+
 13 Aug 2026, PHP 8.6.0beta1
 
 - Core:
diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c
index 4ffe4dfff0e0..7d3ed3c60564 100644
--- a/ext/readline/readline_cli.c
+++ b/ext/readline/readline_cli.c
@@ -529,6 +529,7 @@ static char *cli_completion_generator(const char *text, int index) /* {{{ */
 	} else {
 		char *lc_text;
 		const char *class_name_end;
+		const char *constant_text = text;
 		zend_string *class_name = NULL;
 		zend_class_entry *ce = NULL;
 
@@ -541,6 +542,7 @@ static char *cli_completion_generator(const char *text, int index) /* {{{ */
 				zend_string_release_ex(class_name, 0);
 				return NULL;
 			}
+			constant_text = class_name_end + 2;
 			lc_text = zend_str_tolower_dup(class_name_end + 2, textlen - 2 - class_name_len);
 			textlen -= (class_name_len + 2);
 		} else {
@@ -557,7 +559,7 @@ static char *cli_completion_generator(const char *text, int index) /* {{{ */
 				ZEND_FALLTHROUGH;
 			case 2:
 			case 3:
-				retval = cli_completion_generator_define(text, textlen, &cli_completion_state, ce ? &ce->constants_table : EG(zend_constants));
+				retval = cli_completion_generator_define(constant_text, textlen, &cli_completion_state, ce ? &ce->constants_table : EG(zend_constants));
 				if (retval || ce) {
 					break;
 				}
diff --git a/ext/readline/tests/readline_cli_completion_class_constant.phpt b/ext/readline/tests/readline_cli_completion_class_constant.phpt
new file mode 100644
index 000000000000..1d4e6228df01
--- /dev/null
+++ b/ext/readline/tests/readline_cli_completion_class_constant.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Interactive shell: class constant completion
+--EXTENSIONS--
+readline
+--SKIPIF--
+<?php
+if (READLINE_LIB !== "readline") die('skip readline only');
+if (!function_exists('shell_exec')) die('skip shell_exec() not available');
+?>
+--FILE--
+<?php
+$php = getenv('TEST_PHP_EXECUTABLE_ESCAPED');
+$ini = getenv('TEST_PHP_EXTRA_ARGS');
+
+putenv('TERM=VT100');
+putenv('INPUTRC=/dev/null');
+
+$code = <<<'PHP'
+class Foo {
+    public const FooBar = "wrong_constant\n";
+    public const Zed = "zed_ok\n";
+}
+echo strtoupper(Foo::Ze	);
+exit
+PHP;
+
+echo shell_exec("echo " . escapeshellarg($code) . " | $php $ini -a");
+?>
+--EXPECTF--
+%AInteractive shell%AZED_OK%A
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.