[php-src] master: Zend: improve error message when using array or callable as types with namespace components

From: Date: Wed, 14 Oct 2026 21:48:49 +0000
Subject: [php-src] master: Zend: improve error message when using array or callable as types with namespace components
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142293@lists.php.net to get a copy of this message
Author: Gina Peter Banyard (Girgias) Date: 2026-10-14T22:48:35+01:00 Commit: https://github.com/php/php-src/commit/f99f5c4ab2aa2e109c579458ae54b1ce7787549e Raw diff: https://github.com/php/php-src/commit/f99f5c4ab2aa2e109c579458ae54b1ce7787549e.diff Zend: improve error message when using array or callable as types with namespace components Changed paths: M Zend/tests/type_declarations/builtin/fully_qualified_array.phpt M Zend/tests/type_declarations/builtin/namespace_relative_array.phpt M Zend/tests/type_declarations/callable/fully_qualified_callable.phpt M Zend/tests/type_declarations/callable/namespace_relative_callable.phpt M Zend/zend_compile.c Diff: diff --git a/Zend/tests/type_declarations/builtin/fully_qualified_array.phpt b/Zend/tests/type_declarations/builtin/fully_qualified_array.phpt index c0ba1051b98e..5af78a1bdb1c 100644 --- a/Zend/tests/type_declarations/builtin/fully_qualified_array.phpt +++ b/Zend/tests/type_declarations/builtin/fully_qualified_array.phpt @@ -10,4 +10,4 @@ foo(1); ?> --EXPECTF-- -Fatal error: Cannot use "array" as a type name as it is reserved in %s on line %d +Fatal error: Type declaration 'array' must be unqualified in %s on line %d diff --git a/Zend/tests/type_declarations/builtin/namespace_relative_array.phpt b/Zend/tests/type_declarations/builtin/namespace_relative_array.phpt index 2480620074f7..8db15fe5269f 100644 --- a/Zend/tests/type_declarations/builtin/namespace_relative_array.phpt +++ b/Zend/tests/type_declarations/builtin/namespace_relative_array.phpt @@ -8,4 +8,4 @@ test(0); ?> --EXPECTF-- -Fatal error: Cannot use "array" as a type name as it is reserved in %s on line %d +Fatal error: Type declaration 'array' must be unqualified in %s on line %d diff --git a/Zend/tests/type_declarations/callable/fully_qualified_callable.phpt b/Zend/tests/type_declarations/callable/fully_qualified_callable.phpt index 405125b207a1..9570ab8c82a8 100644 --- a/Zend/tests/type_declarations/callable/fully_qualified_callable.phpt +++ b/Zend/tests/type_declarations/callable/fully_qualified_callable.phpt @@ -7,4 +7,4 @@ function test($i): \callable {} ?> --EXPECTF-- -Fatal error: Cannot use "callable" as a type name as it is reserved in %s on line %d +Fatal error: Type declaration 'callable' must be unqualified in %s on line %d diff --git a/Zend/tests/type_declarations/callable/namespace_relative_callable.phpt b/Zend/tests/type_declarations/callable/namespace_relative_callable.phpt index ccf67a0adc86..45afcf6e5b0b 100644 --- a/Zend/tests/type_declarations/callable/namespace_relative_callable.phpt +++ b/Zend/tests/type_declarations/callable/namespace_relative_callable.phpt @@ -7,4 +7,4 @@ function test($i): namespace\callable {} ?> --EXPECTF-- -Fatal error: Cannot use "callable" as a type name as it is reserved in %s on line %d +Fatal error: Type declaration 'callable' must be unqualified in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 032105019a27..e4df321fb5e1 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -281,6 +281,9 @@ static const builtin_type_info builtin_types[] = { {ZEND_STRL("iterable"), IS_ITERABLE}, {ZEND_STRL("object"), IS_OBJECT}, {ZEND_STRL("mixed"), IS_MIXED}, + /* Should be handled as ZEND_TYPE_ASTs but it may have a namespace component */ + {ZEND_STRL("array"), IS_ARRAY}, + {ZEND_STRL("callable"), IS_CALLABLE}, {ZEND_STRL("static"), IS_STATIC}, {NULL, 0, IS_UNDEF} }; @@ -7747,7 +7750,8 @@ static zend_type zend_compile_single_typename(zend_ast *ast) ZSTR_VAL(zend_string_tolower(type_name))); } - ZEND_ASSERT(type_code != IS_STATIC && "unqualified static type should have been handled by ZEND_AST_TYPE branch"); + ZEND_ASSERT(type_code != IS_STATIC && type_code != IS_ARRAY && type_code != IS_CALLABLE + && "unqualified array/callable/static type should have been handled by ZEND_AST_TYPE branch"); /* Transform iterable into a type union alias */ if (type_code == IS_ITERABLE) {

« previous php.cvs (#142293) next »