mirror of
https://github.com/php/php-src.git
synced 2026-04-11 18:13:00 +02:00
Promote warning to exception in file_get_contents() function
This commit is contained in:
@@ -543,8 +543,8 @@ PHP_FUNCTION(file_get_contents)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (ZEND_NUM_ARGS() == 5 && maxlen < 0) {
|
||||
php_error_docref(NULL, E_WARNING, "length must be greater than or equal to zero");
|
||||
RETURN_FALSE;
|
||||
zend_value_error("Length must be greater than or equal to zero");
|
||||
return;
|
||||
}
|
||||
|
||||
context = php_stream_context_from_zval(zcontext, 0);
|
||||
|
||||
@@ -20,8 +20,12 @@ print( file_get_contents("/no/such/file/or/dir") );
|
||||
create_files($file_path, 1, "text", 0755, 100, "w", "file", 1, "byte");
|
||||
$file_handle = fopen($file_path."/file_put_contents_error.tmp", "w");
|
||||
|
||||
echo "\n-- Testing for invalid negative maxlen values --";
|
||||
var_dump( file_get_contents($file_path."/file1.tmp", FALSE, $file_handle, 0, -5) );
|
||||
echo "\n-- Testing for invalid negative maxlen values --\n";
|
||||
try {
|
||||
file_get_contents($file_path."/file1.tmp", FALSE, $file_handle, 0, -5);
|
||||
} catch (ValueError $exception) {
|
||||
echo $exception->getMessage() . "\n";
|
||||
}
|
||||
|
||||
delete_files($file_path, 1);
|
||||
fclose($file_handle);
|
||||
@@ -47,7 +51,6 @@ if(file_exists($file_path."/file_put_contents1.tmp")) {
|
||||
Warning: file_get_contents(/no/such/file/or/dir): failed to open stream: No such file or directory in %s on line %d
|
||||
|
||||
-- Testing for invalid negative maxlen values --
|
||||
Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d
|
||||
bool(false)
|
||||
Length must be greater than or equal to zero
|
||||
|
||||
*** Done ***
|
||||
|
||||
@@ -7,7 +7,11 @@ file_get_contents() test using negative parameter for length (last parameter)
|
||||
display_errors=false
|
||||
--FILE--
|
||||
<?php
|
||||
var_dump(file_get_contents("http://checkip.dyndns.com",null,null,0,-1));
|
||||
try {
|
||||
file_get_contents("http://checkip.dyndns.com",null,null,0,-1);
|
||||
} catch (ValueError $exception) {
|
||||
echo $exception->getMessage() . "\n";
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(false)
|
||||
Length must be greater than or equal to zero
|
||||
|
||||
@@ -20,9 +20,13 @@ print( file_get_contents("/no/such/file/or/dir") );
|
||||
|
||||
$file_handle = fopen($file_path."/file_put_contents.tmp", "w");
|
||||
|
||||
echo "\n-- Testing for invalid negative maxlen values --";
|
||||
echo "\n-- Testing for invalid negative maxlen values --\n";
|
||||
file_put_contents($file_path."/file_put_contents1.tmp", "Garbage data in the file");
|
||||
var_dump( file_get_contents($file_path."/file_put_contents1.tmp", FALSE, NULL, 0, -5) );
|
||||
try {
|
||||
file_get_contents($file_path."/file_put_contents1.tmp", FALSE, NULL, 0, -5);
|
||||
} catch (ValueError $exception) {
|
||||
echo $exception->getMessage() . "\n";
|
||||
}
|
||||
|
||||
fclose($file_handle);
|
||||
|
||||
@@ -43,7 +47,6 @@ unlink($file_path."/file_put_contents1.tmp");
|
||||
Warning: file_get_contents(/no/such/file/or/dir): failed to open stream: No such file or directory in %s on line %d
|
||||
|
||||
-- Testing for invalid negative maxlen values --
|
||||
Warning: file_get_contents(): length must be greater than or equal to zero in %s on line %d
|
||||
bool(false)
|
||||
Length must be greater than or equal to zero
|
||||
|
||||
*** Done ***
|
||||
|
||||
Reference in New Issue
Block a user