[php-src] master: ext/readline: declare true as the return type of readline_completion_function() (#23433)

Louis-Arnaud via GitHub <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Louis-Arnaud (lacatoire)
Committer: GitHub (web-flow)
Pusher: LamentXU123
Date: 2026-08-25T23:36:54+08:00

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

ext/readline: declare true as the return type of readline_completion_function() (#23433)

The returned value was RETURN_BOOL(rl_attempted_completion_function !=
NULL) on the line right after that variable is assigned the address of
a static function, so it is true unconditionally. Return true directly
and declare it.

Changed paths:
  M  UPGRADING
  M  ext/readline/readline.c
  M  ext/readline/readline.stub.php
  M  ext/readline/readline_arginfo.h


Diff:

diff --git a/UPGRADING b/UPGRADING
index f015399f645e..f3b4ed8b99fa 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -652,6 +652,12 @@ PHP 8.6 UPGRADE NOTES
 - Phar:
   . Phar::mungServer() now supports reference values.
 
+- Readline:
+  . readline_completion_function() now declares true as its return type. The
+    function assigns a static callback and then tests whether the assignment
+    landed, which is a tautology; an invalid callback throws a TypeError via
+    ZPP before the function body is reached.
+
 - Sockets:
   . socket_addrinfo_lookup() now has an additional optional argument $error
     when not null, and on failure, gives the error code (one of the EAI_*
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index cbc0ebdd8713..d9ec274996c7 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -489,8 +489,8 @@ PHP_FUNCTION(readline_completion_function)
 
 	/* NOTE: The rl_attempted_completion_function variable (and others) are part of the readline library, not php */
 	rl_attempted_completion_function = php_readline_completion_cb;
-	
-	RETURN_BOOL(rl_attempted_completion_function != NULL);
+
+	RETURN_TRUE;
 }
 
 /* }}} */
diff --git a/ext/readline/readline.stub.php b/ext/readline/readline.stub.php
index be445df21415..4dae1237c605 100644
--- a/ext/readline/readline.stub.php
+++ b/ext/readline/readline.stub.php
@@ -29,7 +29,7 @@ function readline_read_history(?string $filename = null): bool {}
 
 function readline_write_history(?string $filename = null): bool {}
 
-function readline_completion_function(callable $callback): bool {}
+function readline_completion_function(callable $callback): true {}
 
 
 #ifdef HAVE_RL_CALLBACK_READ_CHAR
diff --git a/ext/readline/readline_arginfo.h b/ext/readline/readline_arginfo.h
index 689d5f762eef..1ce08c443eeb 100644
--- a/ext/readline/readline_arginfo.h
+++ b/ext/readline/readline_arginfo.h
@@ -1,5 +1,5 @@
 /* This is a generated file, edit readline.stub.php instead.
- * Stub hash: 7a314f75d9a89a9ea4d525515bb6bacdf7be6746 */
+ * Stub hash: 848e798481f62ee09cfd8cc3dfa6b0814cfdd979 */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_readline, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
 	ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prompt, IS_STRING, 1, "null")
@@ -28,7 +28,7 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_readline_write_history arginfo_readline_read_history
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_completion_function, 0, 1, _IS_BOOL, 0)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_readline_completion_function, 0, 1, IS_TRUE, 0)
 	ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
 ZEND_END_ARG_INFO()
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.