1
0
mirror of https://github.com/php/php-src.git synced 2026-03-29 19:52:20 +02:00

Promote warnings to errors in dirname()

This commit is contained in:
George Peter Banyard
2019-08-22 11:58:57 +02:00
parent 698491d98a
commit fe44e1637a
4 changed files with 23 additions and 13 deletions

View File

@@ -1619,7 +1619,7 @@ PHPAPI size_t php_dirname(char *path, size_t len)
}
/* }}} */
/* {{{ proto string|null dirname(string path[, int levels])
/* {{{ proto string dirname(string path[, int levels])
Returns the directory name component of the path */
PHP_FUNCTION(dirname)
{
@@ -1644,7 +1644,7 @@ PHP_FUNCTION(dirname)
ZSTR_LEN(ret) = zend_dirname(ZSTR_VAL(ret), str_len);
#endif
} else if (levels < 1) {
php_error_docref(NULL, E_WARNING, "Invalid argument, levels must be >= 1");
zend_throw_error(NULL, "Invalid argument, levels must be >= 1");
zend_string_efree(ret);
return;
} else {

View File

@@ -8,13 +8,15 @@ Test dirname() function : error conditions
echo "*** Testing error conditions ***\n";
// Bad arg
var_dump( dirname("/var/tmp/bar.gz", 0) );
try {
dirname("/var/tmp/bar.gz", 0);
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
echo "Done\n";
?>
--EXPECTF--
*** Testing error conditions ***
Warning: dirname(): Invalid argument, levels must be >= 1 in %s on line %d
NULL
Invalid argument, levels must be >= 1
Done

View File

@@ -11,14 +11,17 @@ if((substr(PHP_OS, 0, 3) == "WIN"))
Description: Returns directory name component of path.
*/
for ($i=0 ; $i<5 ; $i++) {
var_dump(dirname("/foo/bar/baz", $i));
try {
var_dump(dirname("/foo/bar/baz", $i));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
var_dump(dirname("/foo/bar/baz", PHP_INT_MAX));
?>
Done
--EXPECTF--
Warning: dirname(): Invalid argument, levels must be >= 1 in %sdirname_multi.php on line %d
NULL
Invalid argument, levels must be >= 1
string(8) "/foo/bar"
string(4) "/foo"
string(1) "/"

View File

@@ -10,17 +10,22 @@ if((substr(PHP_OS, 0, 3) != "WIN"))
/* Prototype: string dirname ( string $path [, int nb]);
Description: Returns directory name component of path.
*/
for ($i=0 ; $i<5 ; $i++) {
var_dump(dirname("/foo/bar/baz", $i));
try {
var_dump(dirname("/foo/bar/baz", $i));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}
}
var_dump(dirname("/foo/bar/baz", PHP_INT_MAX));
var_dump(dirname("g:/foo/bar/baz", PHP_INT_MAX));
var_dump(dirname("g:foo/bar/baz", PHP_INT_MAX));
?>
Done
--EXPECTF--
Warning: dirname(): Invalid argument, levels must be >= 1 in %sdirname_multi_win.php on line %d
NULL
--EXPECT--
Invalid argument, levels must be >= 1
string(8) "/foo/bar"
string(4) "/foo"
string(1) "\"