From 3c2f26614594311f5c9fab5f3ac9ba537009a969 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Sat, 23 Aug 2025 17:09:34 +0300 Subject: [PATCH] gen_stub: Infer constants' types from values Don't require `@var` with a type when the type can be inferred from a literal value in the stub file. --- Zend/zend_constants.stub.php | 3 --- Zend/zend_constants_arginfo.h | 2 +- build/gen_stub.php | 27 +++++++++++++++++++++++++- ext/date/php_date.stub.php | 12 ------------ ext/date/php_date_arginfo.h | 2 +- ext/dba/dba.stub.php | 1 - ext/dba/dba_arginfo.h | 2 +- ext/dl_test/dl_test.stub.php | 1 - ext/dl_test/dl_test_arginfo.h | 2 +- ext/gd/gd.stub.php | 6 ------ ext/gd/gd_arginfo.h | 2 +- ext/mysqli/mysqli.stub.php | 3 --- ext/mysqli/mysqli_arginfo.h | 2 +- ext/openssl/openssl.stub.php | 1 - ext/openssl/openssl_arginfo.h | 2 +- ext/openssl/openssl_pwhash.stub.php | 9 --------- ext/openssl/openssl_pwhash_arginfo.h | 2 +- ext/sodium/sodium_pwhash.stub.php | 9 --------- ext/sodium/sodium_pwhash_arginfo.h | 2 +- ext/standard/basic_functions.stub.php | 23 ---------------------- ext/standard/basic_functions_arginfo.h | 2 +- ext/standard/file.stub.php | 7 +------ ext/standard/file_arginfo.h | 2 +- ext/standard/password.stub.php | 15 -------------- ext/standard/password_arginfo.h | 2 +- ext/xsl/php_xsl.stub.php | 3 --- ext/xsl/php_xsl_arginfo.h | 2 +- 27 files changed, 40 insertions(+), 106 deletions(-) diff --git a/Zend/zend_constants.stub.php b/Zend/zend_constants.stub.php index 6e791ca4abfd0..e511dc8808668 100644 --- a/Zend/zend_constants.stub.php +++ b/Zend/zend_constants.stub.php @@ -130,17 +130,14 @@ /* Special constants true/false/null. */ /** - * @var bool * @undocumentable */ const TRUE = true; /** - * @var bool * @undocumentable */ const FALSE = false; /** - * @var null * @undocumentable */ const NULL = null; diff --git a/Zend/zend_constants_arginfo.h b/Zend/zend_constants_arginfo.h index 56cb3fe232a82..316b7e37615fd 100644 --- a/Zend/zend_constants_arginfo.h +++ b/Zend/zend_constants_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: bf2f959978bd6cbd7353ca7bfbb95718cdd51cff */ + * Stub hash: 569ccba4e0a93a9ce49c81c76955413188df390e */ static void register_zend_constants_symbols(int module_number) { diff --git a/build/gen_stub.php b/build/gen_stub.php index 5c8407c0564c5..8495f3612ce54 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -4874,7 +4874,32 @@ function parseConstLike( } if ($type === null && $phpDocType === null) { - throw new Exception("Missing type for constant " . $name->__toString()); + if ($const->value instanceof Node\Scalar\Float_) { + $phpDocType = 'float'; + } elseif ($const->value instanceof Node\Scalar\Int_ + || ($const->value instanceof Expr\UnaryMinus + && $const->value->expr instanceof Node\Scalar\Int_ + ) + ) { + $phpDocType = 'int'; + } elseif ($const->value instanceof Node\Scalar\String_) { + $phpDocType = 'string'; + } elseif ($const->value instanceof Expr\ConstFetch + && $const->value->name instanceof Node\Name\FullyQualified + && ( + $const->value->name->name === 'false' + || $const->value->name->name === 'true' + ) + ) { + $phpDocType = 'bool'; + } elseif ($const->value instanceof Expr\ConstFetch + && $const->value->name instanceof Node\Name\FullyQualified + && $const->value->name->name === 'null' + ) { + $phpDocType = 'null'; + } else { + throw new Exception("Missing type for constant " . $name->__toString()); + } } $constType = $type ? Type::fromNode($type) : null; diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index 6eef828b813e8..0b151c9d42163 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -3,74 +3,62 @@ /** @generate-class-entries */ /** - * @var string * @cvalue DATE_FORMAT_RFC3339 */ const DATE_ATOM = "Y-m-d\\TH:i:sP"; /** - * @var string * @cvalue DATE_FORMAT_COOKIE */ const DATE_COOKIE = "l, d-M-Y H:i:s T"; /** - * @var string * @cvalue DATE_FORMAT_ISO8601 */ const DATE_ISO8601 = "Y-m-d\\TH:i:sO"; /** - * @var string * @cvalue DATE_FORMAT_ISO8601_EXPANDED */ const DATE_ISO8601_EXPANDED = "X-m-d\\TH:i:sP"; /** - * @var string * @cvalue DATE_FORMAT_RFC822 */ const DATE_RFC822 = "D, d M y H:i:s O"; /** - * @var string * @cvalue DATE_FORMAT_RFC850 */ const DATE_RFC850 = "l, d-M-y H:i:s T"; /** - * @var string * @cvalue DATE_FORMAT_RFC1036 */ const DATE_RFC1036 = "D, d M y H:i:s O"; /** - * @var string * @cvalue DATE_FORMAT_RFC1123 */ const DATE_RFC1123 = "D, d M Y H:i:s O"; /** - * @var string * @cvalue DATE_FORMAT_RFC7231 */ #[\Deprecated(since: '8.5', message: "as this format ignores the associated timezone and always uses GMT")] const DATE_RFC7231 = "D, d M Y H:i:s \\G\\M\\T"; /** - * @var string * @cvalue DATE_FORMAT_RFC2822 */ const DATE_RFC2822 = "D, d M Y H:i:s O"; /** - * @var string * @cvalue DATE_FORMAT_RFC3339 */ const DATE_RFC3339 = "Y-m-d\\TH:i:sP"; /** - * @var string * @cvalue DATE_FORMAT_RFC3339_EXTENDED */ const DATE_RFC3339_EXTENDED = "Y-m-d\\TH:i:s.vP"; diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index 07a4398ef1cac..5b583772e6582 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: db70e6a06d177d2cb6e4a47379c0b761b248f380 */ + * Stub hash: 16d118b58a713bbea5174c170129aa9f6206de68 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) diff --git a/ext/dba/dba.stub.php b/ext/dba/dba.stub.php index fbc0be8cdadad..ab9758e2c2bb6 100644 --- a/ext/dba/dba.stub.php +++ b/ext/dba/dba.stub.php @@ -14,7 +14,6 @@ final class Connection namespace { #ifdef DBA_LMDB - /** @var int */ const DBA_LMDB_USE_SUB_DIR = 0; /** * @var int diff --git a/ext/dba/dba_arginfo.h b/ext/dba/dba_arginfo.h index c2befedfda7c7..6274c1dd43956 100644 --- a/ext/dba/dba_arginfo.h +++ b/ext/dba/dba_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: da00cabc7b6930f1b834af8978b38945df96212f */ + * Stub hash: d7ff53b73d3921c41ffd8279ea724bcd3a6d8542 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_dba_popen, 0, 2, Dba\\Connection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) diff --git a/ext/dl_test/dl_test.stub.php b/ext/dl_test/dl_test.stub.php index 9c3bbac6b267d..42a30f233f57c 100644 --- a/ext/dl_test/dl_test.stub.php +++ b/ext/dl_test/dl_test.stub.php @@ -5,7 +5,6 @@ * @undocumentable */ -/** @var int */ const DL_TEST_CONST = 42; function dl_test_test1(): void {} diff --git a/ext/dl_test/dl_test_arginfo.h b/ext/dl_test/dl_test_arginfo.h index 1b3b65aa7e677..588d0b1b6e6e1 100644 --- a/ext/dl_test/dl_test_arginfo.h +++ b/ext/dl_test/dl_test_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 75bdb57a45060b123fe48003fef43d2af07726e1 */ + * Stub hash: 3c47a0da41b4548eb68c4124bd54cbac22f60c01 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_dl_test_test1, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() diff --git a/ext/gd/gd.stub.php b/ext/gd/gd.stub.php index 277dd7afeba67..0632724b44f38 100644 --- a/ext/gd/gd.stub.php +++ b/ext/gd/gd.stub.php @@ -449,17 +449,11 @@ * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup. * as error, use the values for now... */ -/** @var int */ const PNG_NO_FILTER = 0x00; -/** @var int */ const PNG_FILTER_NONE = 0x08; -/** @var int */ const PNG_FILTER_SUB = 0x10; -/** @var int */ const PNG_FILTER_UP = 0x20; -/** @var int */ const PNG_FILTER_AVG = 0x40; -/** @var int */ const PNG_FILTER_PAETH = 0x80; /** @var int */ const PNG_ALL_FILTERS = 0x08 | 0x10 | 0x20 | 0x40 | 0x80; diff --git a/ext/gd/gd_arginfo.h b/ext/gd/gd_arginfo.h index 3332fb70bbcfb..87cbfa54b945d 100644 --- a/ext/gd/gd_arginfo.h +++ b/ext/gd/gd_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: bbf4c8d4a3ee5712120bd89f4a2ecc516ea65ff1 */ + * Stub hash: 2cdc0b485d9b62bb9021973d3c8cce0169b21ac0 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() diff --git a/ext/mysqli/mysqli.stub.php b/ext/mysqli/mysqli.stub.php index 89c499ba8aa6a..370da77e62a25 100644 --- a/ext/mysqli/mysqli.stub.php +++ b/ext/mysqli/mysqli.stub.php @@ -589,9 +589,6 @@ */ const MYSQLI_TRANS_COR_NO_RELEASE = UNKNOWN; -/** - * @var bool - */ #[\Deprecated(since: '8.2', message: 'as it is always false')] const MYSQLI_IS_MARIADB = false; diff --git a/ext/mysqli/mysqli_arginfo.h b/ext/mysqli/mysqli_arginfo.h index 52497844fb18b..de7cfa53e0f4f 100644 --- a/ext/mysqli/mysqli_arginfo.h +++ b/ext/mysqli/mysqli_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ce02f0eeb9191e7c92cb8a5e5fcae20fceb0b47c */ + * Stub hash: fecde55745fb219cb15fd35a54a71371ef2b8b7d */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1, MAY_BE_LONG|MAY_BE_STRING) ZEND_ARG_OBJ_INFO(0, mysql, mysqli, 0) diff --git a/ext/openssl/openssl.stub.php b/ext/openssl/openssl.stub.php index 12cbb0ed6184b..94902a4acf0da 100644 --- a/ext/openssl/openssl.stub.php +++ b/ext/openssl/openssl.stub.php @@ -388,7 +388,6 @@ const OPENSSL_DONT_ZERO_PAD_KEY = UNKNOWN; #ifndef OPENSSL_NO_TLSEXT -/** @var int */ const OPENSSL_TLSEXT_SERVER_NAME = 1; #endif diff --git a/ext/openssl/openssl_arginfo.h b/ext/openssl/openssl_arginfo.h index 44415a75892cf..796582c185bb6 100644 --- a/ext/openssl/openssl_arginfo.h +++ b/ext/openssl/openssl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0e6a5f1a5f23602bafd5b7fdb10525c19a9476fc */ + * Stub hash: 8233a8abc8ab7145d905d0fa51478edfe1e55a06 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_openssl_x509_export_to_file, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_TYPE_MASK(0, certificate, OpenSSLCertificate, MAY_BE_STRING, NULL) diff --git a/ext/openssl/openssl_pwhash.stub.php b/ext/openssl/openssl_pwhash.stub.php index c6e3a363c5220..49e2663557dcd 100644 --- a/ext/openssl/openssl_pwhash.stub.php +++ b/ext/openssl/openssl_pwhash.stub.php @@ -3,13 +3,7 @@ /** @generate-class-entries */ #if defined(HAVE_OPENSSL_ARGON2) -/** - * @var string - */ const PASSWORD_ARGON2I = "argon2i"; -/** - * @var string - */ const PASSWORD_ARGON2ID = "argon2id"; /** * @var int @@ -26,9 +20,6 @@ * @cvalue PHP_OPENSSL_PWHASH_THREADS */ const PASSWORD_ARGON2_DEFAULT_THREADS = UNKNOWN; -/** - * @var string - */ const PASSWORD_ARGON2_PROVIDER = "openssl"; #endif diff --git a/ext/openssl/openssl_pwhash_arginfo.h b/ext/openssl/openssl_pwhash_arginfo.h index b4213158a169a..13ce9203f5c32 100644 --- a/ext/openssl/openssl_pwhash_arginfo.h +++ b/ext/openssl/openssl_pwhash_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b6056170a5c8f1a9582c5eef9261a0bd02f7a7e1 */ + * Stub hash: 23ee957ba4945be3a21db58051e548729c3ff44e */ static void register_openssl_pwhash_symbols(int module_number) { diff --git a/ext/sodium/sodium_pwhash.stub.php b/ext/sodium/sodium_pwhash.stub.php index 58d7139c0ebc3..82c04bfa4b1a1 100644 --- a/ext/sodium/sodium_pwhash.stub.php +++ b/ext/sodium/sodium_pwhash.stub.php @@ -3,13 +3,7 @@ /** @generate-class-entries */ #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) -/** - * @var string - */ const PASSWORD_ARGON2I = "argon2i"; -/** - * @var string - */ const PASSWORD_ARGON2ID = "argon2id"; /** * @var int @@ -26,8 +20,5 @@ * @cvalue PHP_SODIUM_PWHASH_THREADS */ const PASSWORD_ARGON2_DEFAULT_THREADS = UNKNOWN; -/** - * @var string - */ const PASSWORD_ARGON2_PROVIDER = "sodium"; #endif diff --git a/ext/sodium/sodium_pwhash_arginfo.h b/ext/sodium/sodium_pwhash_arginfo.h index 465f3090191d1..d559a74fbc1fe 100644 --- a/ext/sodium/sodium_pwhash_arginfo.h +++ b/ext/sodium/sodium_pwhash_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: dd94e709f115ce05df0e25a8cb48c62438bb6d01 */ + * Stub hash: d1e804ceea5e18fc5a4eca50b318d98387b2a470 */ static void register_sodium_pwhash_symbols(int module_number) { diff --git a/ext/standard/basic_functions.stub.php b/ext/standard/basic_functions.stub.php index f909022c0498a..7913ca0e00194 100644 --- a/ext/standard/basic_functions.stub.php +++ b/ext/standard/basic_functions.stub.php @@ -260,87 +260,70 @@ const PHP_QUERY_RFC3986 = UNKNOWN; /** - * @var float * @cvalue M_E */ const M_E = 2.718281828459045; /** - * @var float * @cvalue M_LOG2E */ const M_LOG2E = 1.4426950408889634074; /** - * @var float * @cvalue M_LOG10E */ const M_LOG10E = 0.43429448190325182765; /** - * @var float * @cvalue M_LN2 */ const M_LN2 = 0.69314718055994530942; /** - * @var float * @cvalue M_LN10 */ const M_LN10 = 2.30258509299404568402; /** - * @var float * @cvalue M_PI */ const M_PI = 3.14159265358979323846; /** - * @var float * @cvalue M_PI_2 */ const M_PI_2 = 1.57079632679489661923; /** - * @var float * @cvalue M_PI_4 */ const M_PI_4 = 0.78539816339744830962; /** - * @var float * @cvalue M_1_PI */ const M_1_PI = 0.31830988618379067154; /** - * @var float * @cvalue M_2_PI */ const M_2_PI = 0.63661977236758134308; /** - * @var float * @cvalue M_SQRTPI */ const M_SQRTPI = 1.77245385090551602729; /** - * @var float * @cvalue M_2_SQRTPI */ const M_2_SQRTPI = 1.12837916709551257390; /** - * @var float * @cvalue M_LNPI */ const M_LNPI = 1.14472988584940017414; /** - * @var float * @cvalue M_EULER */ const M_EULER = 0.57721566490153286061; /** - * @var float * @cvalue M_SQRT2 */ const M_SQRT2 = 1.41421356237309504880; /** - * @var float * @cvalue M_SQRT1_2 */ const M_SQRT1_2 = 0.70710678118654752440; /** - * @var float * @cvalue M_SQRT3 */ const M_SQRT3 = 1.73205080756887729352; @@ -383,17 +366,11 @@ * @cvalue PHP_MAX_SALT_LEN */ const CRYPT_SALT_LENGTH = UNKNOWN; -/** @var int */ const CRYPT_STD_DES = 1; -/** @var int */ const CRYPT_EXT_DES = 1; -/** @var int */ const CRYPT_MD5 = 1; -/** @var int */ const CRYPT_BLOWFISH = 1; -/** @var int */ const CRYPT_SHA256 = 1; -/** @var int */ const CRYPT_SHA512 = 1; /* dns.c */ diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h index cced5b0961271..668eca9aadc20 100644 --- a/ext/standard/basic_functions_arginfo.h +++ b/ext/standard/basic_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 01fc9901c45992450d60ceedbb82d3a6fb8500de */ + * Stub hash: f6bf6cdd07080c01d3a0cb08d71409d05b1084f9 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0) diff --git a/ext/standard/file.stub.php b/ext/standard/file.stub.php index 91d2ea08708ec..5e12c43f397c7 100644 --- a/ext/standard/file.stub.php +++ b/ext/standard/file.stub.php @@ -444,14 +444,9 @@ */ const FILE_NO_DEFAULT_CONTEXT = UNKNOWN; -/** - * @var int - */ #[\Deprecated(since: '8.1', message: 'as the constant has no effect')] const FILE_TEXT = 0; -/** - * @var int - */ + #[\Deprecated(since: '8.1', message: 'as the constant has no effect')] const FILE_BINARY = 0; diff --git a/ext/standard/file_arginfo.h b/ext/standard/file_arginfo.h index ee9b2c4ff7d6b..073e7951ad8c3 100644 --- a/ext/standard/file_arginfo.h +++ b/ext/standard/file_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: dde0b40909dbadb565d898338834de7fa689c5e9 */ + * Stub hash: c394e14cd32587ce9ad0503e21c6c4cf5b301697 */ static void register_file_symbols(int module_number) { diff --git a/ext/standard/password.stub.php b/ext/standard/password.stub.php index c3c99117d514c..b4758ef54b126 100644 --- a/ext/standard/password.stub.php +++ b/ext/standard/password.stub.php @@ -2,13 +2,7 @@ /** @generate-class-entries */ -/** - * @var string - */ const PASSWORD_DEFAULT = "2y"; -/** - * @var string - */ const PASSWORD_BCRYPT = "2y"; /** * @var int @@ -17,17 +11,8 @@ const PASSWORD_BCRYPT_DEFAULT_COST = UNKNOWN; #ifdef HAVE_ARGON2LIB -/** - * @var string - */ const PASSWORD_ARGON2I = "argon2i"; -/** - * @var string - */ const PASSWORD_ARGON2ID = "argon2id"; -/** - * @var string - */ const PASSWORD_ARGON2_PROVIDER = "standard"; /** * @var int diff --git a/ext/standard/password_arginfo.h b/ext/standard/password_arginfo.h index fd25fbed67739..ec4876fe2a3cc 100644 --- a/ext/standard/password_arginfo.h +++ b/ext/standard/password_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: aab38646ace967e985c348b78251474693da95a7 */ + * Stub hash: f61df8d477588718e0eb1b055e5a3e138e6bcad3 */ static void register_password_symbols(int module_number) { diff --git a/ext/xsl/php_xsl.stub.php b/ext/xsl/php_xsl.stub.php index 24da81b7d71b8..6fe39c1a606e3 100644 --- a/ext/xsl/php_xsl.stub.php +++ b/ext/xsl/php_xsl.stub.php @@ -2,11 +2,8 @@ /** @generate-class-entries */ -/** @var int */ const XSL_CLONE_AUTO = 0; -/** @var int */ const XSL_CLONE_NEVER = -1; -/** @var int */ const XSL_CLONE_ALWAYS = 1; /** diff --git a/ext/xsl/php_xsl_arginfo.h b/ext/xsl/php_xsl_arginfo.h index 72e7ed0b0a99d..d640d1114a566 100644 --- a/ext/xsl/php_xsl_arginfo.h +++ b/ext/xsl/php_xsl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 5b4ce3f5f7dee60bde803b3c2eb3994777f56914 */ + * Stub hash: cb1005b601e72e8d36d0f6aa5d08872f5c7ea2e6 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_XSLTProcessor_importStylesheet, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, stylesheet, IS_OBJECT, 0)