From 77b60fd492e4f57313b681d7e8716708e6e31e5e Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 4 Aug 2026 00:41:19 +0100 Subject: [PATCH] Zend: remove zend_is_countable() This function is only used once internally, and no usage is reported from a SourceGraph search. [1] [1] https://sourcegraph.com/search?q=context:global+-f:zend_API.c+-f:zend_API.h+zend_is_countable&patternType=keyword&sm=0 --- UPGRADING.INTERNALS | 1 + Zend/zend_API.c | 17 ----------------- Zend/zend_API.h | 2 -- ext/standard/type.c | 15 ++++++++++++++- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 8b4b5912317a..d94a4ce93f5b 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -120,6 +120,7 @@ PHP 8.6 INTERNALS UPGRADE NOTES flags parameter was never used. . The PHP stream function _php_stream_flush() was removed, instead the PHP macro php_stream_flush() is now a proper function. + . The zend_is_countable() function was removed. - Changed: . Internal functions that return by reference are now expected to diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 71754b9ab755..51d823b66569 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -5245,23 +5245,6 @@ ZEND_API bool zend_is_iterable(const zval *iterable) /* {{{ */ } /* }}} */ -ZEND_API bool zend_is_countable(const zval *countable) /* {{{ */ -{ - switch (Z_TYPE_P(countable)) { - case IS_ARRAY: - return 1; - case IS_OBJECT: - if (Z_OBJ_HT_P(countable)->count_elements) { - return 1; - } - - return zend_class_implements_interface(Z_OBJCE_P(countable), zend_ce_countable); - default: - return 0; - } -} -/* }}} */ - static zend_result get_default_via_ast(zval *default_value_zval, const char *default_value) { zend_ast *ast; zend_arena *ast_arena; diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 34c316bca588..c703f4393a8e 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -962,8 +962,6 @@ static zend_always_inline const char *zend_get_object_type_uc(const zend_class_e ZEND_API bool zend_is_iterable(const zval *iterable); -ZEND_API bool zend_is_countable(const zval *countable); - ZEND_API void zend_convert_internal_arg_info(zend_arg_info *new_arg_info, const zend_internal_arg_info *arg_info, bool is_return_info, bool permanent); diff --git a/ext/standard/type.c b/ext/standard/type.c index fc681a3c50a7..dc99dac93dac 100644 --- a/ext/standard/type.c +++ b/ext/standard/type.c @@ -13,6 +13,7 @@ */ #include "php.h" +#include "zend_interfaces.h" /* {{{ Returns the type of the variable */ PHP_FUNCTION(gettype) @@ -458,6 +459,18 @@ PHP_FUNCTION(is_countable) Z_PARAM_ZVAL(var) ZEND_PARSE_PARAMETERS_END(); - RETURN_BOOL(zend_is_countable(var)); + + switch (Z_TYPE_P(var)) { + case IS_ARRAY: + RETURN_TRUE; + case IS_OBJECT: + if (Z_OBJ_HT_P(var)->count_elements) { + RETURN_TRUE; + } + + RETURN_BOOL(zend_class_implements_interface(Z_OBJCE_P(var), zend_ce_countable)); + default: + RETURN_FALSE; + } } /* }}} */