From 2b0fa0dc336fc83f6eb5de880ac738f27091a5ac Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 22 Dec 2024 16:20:43 +0000 Subject: [PATCH 1/2] SplFileObject::fwrite $length param nullable --- ext/spl/spl_directory.c | 11 +++++++---- ext/spl/spl_directory.stub.php | 2 +- ext/spl/spl_directory_arginfo.h | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index b14d182dcd763..e36d11bdc105c 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -2606,15 +2606,18 @@ PHP_METHOD(SplFileObject, fwrite) char *str; size_t str_len; zend_long length = 0; + bool length_is_null = true; ssize_t written; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &str, &str_len, &length) == FAILURE) { - RETURN_THROWS(); - } + ZEND_PARSE_PARAMETERS_START(1, 2) + Z_PARAM_STRING(str, str_len) + Z_PARAM_OPTIONAL + Z_PARAM_LONG_OR_NULL(length, length_is_null) + ZEND_PARSE_PARAMETERS_END(); CHECK_SPL_FILE_OBJECT_IS_INITIALIZED(intern); - if (ZEND_NUM_ARGS() > 1) { + if (!length_is_null) { if (length >= 0) { str_len = MIN((size_t)length, str_len); } else { diff --git a/ext/spl/spl_directory.stub.php b/ext/spl/spl_directory.stub.php index a53a50eb71f98..e8ea5c4af9e81 100644 --- a/ext/spl/spl_directory.stub.php +++ b/ext/spl/spl_directory.stub.php @@ -283,7 +283,7 @@ public function fpassthru(): int {} public function fscanf(string $format, mixed &...$vars): array|int|null {} /** @tentative-return-type */ - public function fwrite(string $data, int $length = 0): int|false {} + public function fwrite(string $data, ?int $length = null): int|false {} /** @tentative-return-type */ public function fstat(): array {} diff --git a/ext/spl/spl_directory_arginfo.h b/ext/spl/spl_directory_arginfo.h index 9874b756f4a77..e9287e7ea9483 100644 --- a/ext/spl/spl_directory_arginfo.h +++ b/ext/spl/spl_directory_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: c8c3c642d6f8c19a83f6a94ede5b6138a969bc12 */ + * Stub hash: 06a7809f97dde10e800382fec03a9bb308918bb3 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -227,7 +227,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_MASK_EX(arginfo_class_SplFileObject_fwrite, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "0") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null") ZEND_END_ARG_INFO() #define arginfo_class_SplFileObject_fstat arginfo_class_SplFileInfo___debugInfo From de73f431d9662f763011331c3d429aa172a9dadd Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Sun, 22 Dec 2024 23:53:26 +0000 Subject: [PATCH 2/2] Add UPGRADING entry --- UPGRADING | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UPGRADING b/UPGRADING index 18b2b460768a8..28805e0f824fd 100644 --- a/UPGRADING +++ b/UPGRADING @@ -57,6 +57,8 @@ PHP 8.5 UPGRADE NOTES - SPL: . ArrayObject no longer accepts enums, as modifying the $name or $value properties can break engine assumptions. + . SplFileObject::fwrite's parameter $length is now nullable. The default + value changed from 0 to null. ======================================== 2. New Features @@ -99,7 +101,7 @@ PHP 8.5 UPGRADE NOTES ======================================== - Zlib: - . The "use_include_path" argument for the + . The "use_include_path" argument for the gzfile, gzopen and readgzfile functions had been changed from int to boolean.