Skip to content

ext/standard: Deprecate passing null to readdir(), rewinddir(), and closedir() #19423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ PHP_FUNCTION(dir)
static php_stream* php_dir_get_directory_stream_from_user_arg(php_stream *dir_stream)
{
if (dir_stream == NULL) {
php_error_docref(NULL, E_DEPRECATED,
"Passing null is deprecated, instead the last opened directory stream should be provided");
Copy link

@alecpl alecpl Aug 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "the last opened" should be replaced by "a" here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The objective of the message is to indicate how to get rid of the deprecation without altering behaviour.
Replacing "the last opened" by "a" is unhelpful here.

if (UNEXPECTED(DIRG(default_dir) == NULL)) {
zend_type_error("No resource supplied");
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions ext/standard/tests/dir/closedir_basic-win32-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ rmdir($dir_path);
*** Testing closedir() : basic functionality ***

-- Call closedir() with no arguments: --

Deprecated: closedir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
NULL
-- Check Directory Handle: --
resource(%d) of type (Unknown)
Expand Down
2 changes: 2 additions & 0 deletions ext/standard/tests/dir/closedir_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ rmdir($dir_path);
*** Testing closedir() : basic functionality ***

-- Call closedir() with no arguments: --

Deprecated: closedir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
NULL
-- Check Directory Handle: --
resource(%d) of type (Unknown)
Expand Down
3 changes: 2 additions & 1 deletion ext/standard/tests/dir/closedir_without_arg.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ try {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
--EXPECTF--
Deprecated: closedir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
No resource supplied
12 changes: 12 additions & 0 deletions ext/standard/tests/dir/readdir_basic-win32-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ string(9) "file3.tmp"

-- Call readdir() without $path argument --
resource(%d) of type (stream)

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
string(1) "."
string(2) ".."
string(9) "file1.tmp"
Expand Down
12 changes: 12 additions & 0 deletions ext/standard/tests/dir/readdir_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ string(9) "file3.tmp"

-- Call readdir() without $path argument --
resource(%d) of type (stream)

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
string(1) "."
string(2) ".."
string(9) "file1.tmp"
Expand Down
16 changes: 15 additions & 1 deletion ext/standard/tests/dir/readdir_variation6-win32-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ closedir();
$dir_path = __DIR__ . "/私はガラスを食べられますreaddir_variation6";
rmdir($dir_path);
?>
--EXPECT--
--EXPECTF--
*** Testing readdir() : usage variations ***

-- Reading Directory Contents with Previous Handle --
Expand All @@ -72,8 +72,22 @@ string(59) "私はガラスを食べられますreaddir_variation62.tmp"
string(59) "私はガラスを食べられますreaddir_variation63.tmp"

-- Reading Directory Contents with Current Handle (no arguments supplied) --

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
string(1) "."
string(2) ".."
string(59) "私はガラスを食べられますreaddir_variation61.tmp"
string(59) "私はガラスを食べられますreaddir_variation62.tmp"
string(59) "私はガラスを食べられますreaddir_variation63.tmp"

Deprecated: closedir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
16 changes: 15 additions & 1 deletion ext/standard/tests/dir/readdir_variation6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ closedir();
$dir_path = __DIR__ . "/readdir_variation6";
rmdir($dir_path);
?>
--EXPECT--
--EXPECTF--
*** Testing readdir() : usage variations ***

-- Reading Directory Contents with Previous Handle --
Expand All @@ -66,8 +66,22 @@ string(23) "readdir_variation62.tmp"
string(23) "readdir_variation63.tmp"

-- Reading Directory Contents with Current Handle (no arguments supplied) --

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
string(1) "."
string(2) ".."
string(23) "readdir_variation61.tmp"
string(23) "readdir_variation62.tmp"
string(23) "readdir_variation63.tmp"

Deprecated: closedir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
12 changes: 12 additions & 0 deletions ext/standard/tests/dir/rewinddir_basic-win32-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ NULL
bool(true)

-- Read and rewind second directory (no argument supplied) --

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
array(3) {
[0]=>
string(1) "."
Expand All @@ -90,5 +98,9 @@ array(3) {
[2]=>
string(45) "私はガラスを食べられますfile2.tmp"
}

Deprecated: rewinddir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
NULL

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
bool(true)
12 changes: 12 additions & 0 deletions ext/standard/tests/dir/rewinddir_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ NULL
bool(true)

-- Read and rewind second directory (no argument supplied) --

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
array(3) {
[0]=>
string(1) "."
Expand All @@ -84,5 +92,9 @@ array(3) {
[2]=>
string(9) "file2.tmp"
}

Deprecated: rewinddir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
NULL

Deprecated: readdir(): Passing null is deprecated, instead the last opened directory stream should be provided in %s on line %d
bool(true)