Skip to content

Commit b3d7252

Browse files
Girgiaskrakjoe
authored andcommitted
Promote warnings to errors in dir stdlib extension
1 parent 9bd0cce commit b3d7252

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

ext/standard/dir.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ PHP_FUNCTION(closedir)
266266
FETCH_DIRP();
267267

268268
if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
269-
php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
270-
RETURN_FALSE;
269+
zend_type_error("%d is not a valid Directory resource", dirp->res->handle);
270+
return;
271271
}
272272

273273
res = dirp->res;
@@ -382,8 +382,8 @@ PHP_FUNCTION(rewinddir)
382382
FETCH_DIRP();
383383

384384
if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
385-
php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
386-
RETURN_FALSE;
385+
zend_type_error("%d is not a valid Directory resource", dirp->res->handle);
386+
return;
387387
}
388388

389389
php_stream_rewinddir(dirp);
@@ -401,8 +401,8 @@ PHP_NAMED_FUNCTION(php_if_readdir)
401401
FETCH_DIRP();
402402

403403
if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
404-
php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
405-
RETURN_FALSE;
404+
zend_type_error("%d is not a valid Directory resource", dirp->res->handle);
405+
return;
406406
}
407407

408408
if (php_stream_readdir(dirp, &entry)) {
@@ -566,8 +566,8 @@ PHP_FUNCTION(scandir)
566566
ZEND_PARSE_PARAMETERS_END();
567567

568568
if (dirn_len < 1) {
569-
php_error_docref(NULL, E_WARNING, "Directory name cannot be empty");
570-
RETURN_FALSE;
569+
zend_throw_error(NULL, "Directory name cannot be empty");
570+
return;
571571
}
572572

573573
if (zcontext) {

ext/standard/tests/dir/closedir_variation3.phpt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ echo "\n-- Open a file using fopen() --\n";
1818
var_dump($fp = fopen(__FILE__, 'r'));
1919

2020
echo "\n-- Try to close the file pointer using closedir() --\n";
21-
var_dump(closedir($fp));
22-
21+
try {
22+
var_dump(closedir($fp));
23+
} catch (\TypeError $e) {
24+
echo $e->getMessage() . "\n";
25+
}
2326
echo "\n-- Check file pointer: --\n";
2427
var_dump($fp);
2528

@@ -35,9 +38,7 @@ if(is_resource($fp)) {
3538
resource(%d) of type (stream)
3639

3740
-- Try to close the file pointer using closedir() --
38-
39-
Warning: closedir(): %d is not a valid Directory resource in %s on line %d
40-
bool(false)
41+
%d is not a valid Directory resource
4142

4243
-- Check file pointer: --
4344
resource(%d) of type (stream)

ext/standard/tests/dir/readdir_variation7.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ echo "*** Testing readdir() : usage variations ***\n";
1515

1616
// get a resource variable
1717
var_dump($fp = fopen(__FILE__, "r"));
18-
var_dump( readdir($fp) );
18+
try {
19+
var_dump( readdir($fp) );
20+
} catch (\TypeError $e) {
21+
echo $e->getMessage() . "\n";
22+
}
1923

2024
?>
2125
===DONE===
2226
--EXPECTF--
2327
*** Testing readdir() : usage variations ***
2428
resource(%d) of type (stream)
25-
26-
Warning: readdir(): %d is not a valid Directory resource in %s on line %d
27-
bool(false)
29+
%d is not a valid Directory resource
2830
===DONE===

ext/standard/tests/dir/rewinddir_variation3.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ echo "\n-- Open a file using fopen --\n";
1818
var_dump($fp = fopen(__FILE__, 'r'));
1919

2020
$result1 = fread($fp, 5);
21-
var_dump(rewinddir($fp));
21+
22+
try {
23+
var_dump(rewinddir($fp));
24+
} catch (\TypeError $e) {
25+
echo $e->getMessage() . "\n";
26+
}
2227
$result2 = fread($fp, 5);
2328

2429
echo "\n-- Check if rewinddir() has repositioned the file pointer --\n";
@@ -34,9 +39,7 @@ if ($result1 === $result2) {
3439

3540
-- Open a file using fopen --
3641
resource(%d) of type (stream)
37-
38-
Warning: rewinddir(): %d is not a valid Directory resource in %s on line %d
39-
bool(false)
42+
%d is not a valid Directory resource
4043

4144
-- Check if rewinddir() has repositioned the file pointer --
4245
rewinddir() does not work on file pointers

0 commit comments

Comments
 (0)