com php-src: Promote warning to exception in file_get_conte nts() function: ext/standard/file.c ext/standard/ tests/file/file_get_contents_error.phpt
ext/standard/ tests/file/file_get_contents_error002.phpt ext/ standard/tests/file/file_get_contents_file_put_conten ts_error.phpt

From: Date: Thu, 05 Dec 2019 07:32:29 +0000
Subject: com php-src: Promote warning to exception in file_get_conte nts() function: ext/standard/file.c ext/standard/ tests/file/file_get_contents_error.phpt
ext/standard/ tests/file/file_get_contents_error002.phpt ext/ standard/tests/file/file_get_contents_file_put_conten ts_error.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109389@lists.php.net to get a copy of this message
Commit: 5898e8ef3c1bfb2aaa040bc9b86c6c402015865d Author: Máté Kocsis <kocsismate@woohoolabs.com> Wed, 20 Nov 2019 02:29:18 +0100 Parents: ad4d6634f49bfb6ce382e9b9a3d50492d41687ea Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5898e8ef3c1bfb2aaa040bc9b86c6c402015865d Log: Promote warning to exception in file_get_contents() function Changed paths: M ext/standard/file.c M ext/standard/tests/file/file_get_contents_error.phpt M ext/standard/tests/file/file_get_contents_error002.phpt M ext/standard/tests/file/file_get_contents_file_put_contents_error.phpt Diff: diff --git a/ext/standard/file.c b/ext/standard/file.c index c7727a65b8f..58bbbaa52c8 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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); diff --git a/ext/standard/tests/file/file_get_contents_error.phpt b/ext/standard/tests/file/file_get_contents_error.phpt index 9757b3be2a2..8304105ccce 100644 --- a/ext/standard/tests/file/file_get_contents_error.phpt +++ b/ext/standard/tests/file/file_get_contents_error.phpt @@ -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 *** diff --git a/ext/standard/tests/file/file_get_contents_error002.phpt b/ext/standard/tests/file/file_get_contents_error002.phpt index 8ca11626723..4c9faf91ea1 100644 --- a/ext/standard/tests/file/file_get_contents_error002.phpt +++ b/ext/standard/tests/file/file_get_contents_error002.phpt @@ -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 diff --git a/ext/standard/tests/file/file_get_contents_file_put_contents_error.phpt b/ext/standard/tests/file/file_get_contents_file_put_contents_error.phpt index a50317e8dbb..b111ff9f5da 100644 --- a/ext/standard/tests/file/file_get_contents_file_put_contents_error.phpt +++ b/ext/standard/tests/file/file_get_contents_file_put_contents_error.phpt @@ -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 ***

« previous php.cvs (#109389) next »