Skip to content

Commit

Permalink
SplFileObject::fwrite $length param nullable (#17242)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-tekiela authored Dec 22, 2024
1 parent f646905 commit bf5e6c5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 3 additions & 1 deletion UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down
11 changes: 7 additions & 4 deletions ext/spl/spl_directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ext/spl/spl_directory.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
4 changes: 2 additions & 2 deletions ext/spl/spl_directory_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bf5e6c5

Please sign in to comment.