}
?>
+===Done===
--EXPECTF--
*** Testing error conditions for fopen(), fclsoe() & feof() ***
Warning: fopen() expects at least 2 parameters, 0 given in %s on line %d
bool(false)
-Warning: fclose(): 5 is not a valid stream resource in %s on line %d
+Warning: fclose(): %d is not a valid stream resource in %s on line %d
bool(false)
Warning: fclose(): supplied argument is not a valid stream resource in %s on line %d
Warning: Wrong parameter count for fclose() in %s on line %d
NULL
-Warning: feof(): 5 is not a valid stream resource in %s on line %d
+Warning: feof(): %d is not a valid stream resource in %s on line %d
bool(false)
Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
Warning: feof(): supplied argument is not a valid stream resource in %s on line %d
bool(false)
+===Done===
\ No newline at end of file
*/
echo "*** Testing file_get_contents() : variation ***\n";
+
/* An array of filenames */
$names_arr = array(
- /* Invalid args */
- -1,
- TRUE,
- FALSE,
- NULL,
- "",
- " ",
- "\0",
- array(),
-
- /* prefix with path separator of a non existing directory*/
- "/no/such/file/dir",
- "php/php"
+ /* Invalid args */
+ "-1" => -1,
+ "TRUE" => TRUE,
+ "FALSE" => FALSE,
+ "NULL" => NULL,
+ "\"\"" => "",
+ "\" \"" => " ",
+ "\\0" => "\0",
+ "array()" => array(),
+
+ /* prefix with path separator of a non existing directory*/
+ "/no/such/file/dir" => "/no/such/file/dir",
+ "php/php"=> "php/php"
);
-for( $i=0; $i<count($names_arr); $i++ ) {
- echo "-- Iteration $i --\n";
- var_dump(file_get_contents($names_arr[$i]));
+foreach($names_arr as $key =>$value) {
+ echo "\n-- Filename: $key --\n";
+ var_dump(file_get_contents($value));
}
-echo "\n*** Done ***\n";
?>
+===Done===
--EXPECTF--
*** Testing file_get_contents() : variation ***
--- Iteration 0 --
+
+-- Filename: -1 --
Warning: file_get_contents(-1): failed to open stream: No such file or directory in %s on line %d
bool(false)
--- Iteration 1 --
+
+-- Filename: TRUE --
Warning: file_get_contents(1): failed to open stream: No such file or directory in %s on line %d
bool(false)
--- Iteration 2 --
+
+-- Filename: FALSE --
+
+Warning: file_get_contents(): Filename cannot be empty in %s on line %d
bool(false)
--- Iteration 3 --
+
+-- Filename: NULL --
+
+Warning: file_get_contents(): Filename cannot be empty in %s on line %d
bool(false)
--- Iteration 4 --
+
+-- Filename: "" --
+
+Warning: file_get_contents(): Filename cannot be empty in %s on line %d
bool(false)
--- Iteration 5 --
+
+-- Filename: " " --
Warning: file_get_contents( ): failed to open stream: Permission denied in %s on line %d
bool(false)
--- Iteration 6 --
+
+-- Filename: \0 --
+
+Warning: file_get_contents(): Filename cannot be empty in %s on line %d
bool(false)
--- Iteration 7 --
+
+-- Filename: array() --
Warning: file_get_contents() expects parameter 1 to be string, array given in %s on line %d
NULL
--- Iteration 8 --
+
+-- Filename: /no/such/file/dir --
Warning: file_get_contents(/no/such/file/dir): failed to open stream: No such file or directory in %s on line %d
bool(false)
--- Iteration 9 --
+
+-- Filename: php/php --
Warning: file_get_contents(php/php): failed to open stream: No such file or directory in %s on line %d
bool(false)
-
-*** Done ***
\ No newline at end of file
+===Done===
\ No newline at end of file
/* An array of filenames */
$names_arr = array(
- -1,
- TRUE,
- FALSE,
- NULL,
- "",
- " ",
- "\0",
- array(),
-
- //the next 2 generate java messages so we don't replicate the php messages
- "/no/such/file/dir",
- "php/php"
+ "-1" => -1,
+ "TRUE" => TRUE,
+ "FALSE" => FALSE,
+ "NULL" => NULL,
+ "\"\"" => "",
+ "\" \"" => " ",
+ "\\0" => "\0",
+ "array()" => array(),
+
+ /* prefix with path separator of a non existing directory*/
+ "/no/such/file/dir" => "/no/such/file/dir",
+ "php/php"=> "php/php"
);
-for( $i=0; $i<count($names_arr); $i++ ) {
- echo "-- Iteration $i --\n";
- $res = file_put_contents($names_arr[$i], "Some data");
- if ($res !== false && $res != null) {
- echo "$res bytes written to: $names_arr[$i]\n";
- unlink($names_arr[$i]);
- }
- else {
- echo "Failed to write data to: $names_arr[$i]\n";
- }
-}
-
-echo "\n*** Done ***\n";
+foreach($names_arr as $key =>$value) {
+ echo "\n-- Filename: $key --\n";
+ $res = file_put_contents($value, "Some data");
+ if ($res !== false && $res != null) {
+ echo "$res bytes written to: $value\n";
+ unlink($value);
+ } else {
+ echo "Failed to write data to: $key\n";
+ }
+};
+
?>
+===Done===
--EXPECTF--
*** Testing file_put_contents() : usage variation ***
--- Iteration 0 --
+
+-- Filename: -1 --
9 bytes written to: -1
--- Iteration 1 --
+
+-- Filename: TRUE --
9 bytes written to: 1
--- Iteration 2 --
-Failed to write data to:
--- Iteration 3 --
-Failed to write data to:
--- Iteration 4 --
-Failed to write data to:
--- Iteration 5 --
+
+-- Filename: FALSE --
+
+Warning: file_put_contents(): Filename cannot be empty in %s on line %d
+Failed to write data to: FALSE
+
+-- Filename: NULL --
+
+Warning: file_put_contents(): Filename cannot be empty in %s on line %d
+Failed to write data to: NULL
+
+-- Filename: "" --
+
+Warning: file_put_contents(): Filename cannot be empty in %s on line %d
+Failed to write data to: ""
+
+-- Filename: " " --
Warning: file_put_contents( ): failed to open stream: Permission denied in %s on line %d
-Failed to write data to:
--- Iteration 6 --
-Failed to write data to:%s
--- Iteration 7 --
+Failed to write data to: " "
+
+-- Filename: \0 --
+
+Warning: file_put_contents(): Filename cannot be empty in %s on line %d
+Failed to write data to: \0
+
+-- Filename: array() --
Warning: file_put_contents() expects parameter 1 to be string, array given in %s on line %d
-Failed to write data to: Array
--- Iteration 8 --
+Failed to write data to: array()
+
+-- Filename: /no/such/file/dir --
Warning: file_put_contents(/no/such/file/dir): failed to open stream: %s in %s on line %d
Failed to write data to: /no/such/file/dir
--- Iteration 9 --
+
+-- Filename: php/php --
Warning: file_put_contents(php/php): failed to open stream: %s in %s on line %d
Failed to write data to: php/php
-
-*** Done ***
\ No newline at end of file
+===Done===
\ No newline at end of file
echo "*** Testing readfile() : variation ***\n";
-
/* An array of files */
$names_arr = array(
- /* Invalid args */
- -1,
- TRUE,
- FALSE,
- NULL,
- "",
- " ",
- "\0",
- array(),
+ /* Invalid args */
+ "-1" => -1,
+ "TRUE" => TRUE,
+ "FALSE" => FALSE,
+ "NULL" => NULL,
+ "\"\"" => "",
+ "\" \"" => " ",
+ "\\0" => "\0",
+ "array()" => array(),
/* prefix with path separator of a non existing directory*/
- "/no/such/file/dir",
- "php/php"
+ "/no/such/file/dir" => "/no/such/file/dir",
+ "php/php"=> "php/php"
);
-for( $i=0; $i<count($names_arr); $i++ ) {
- $name = $names_arr[$i];
- echo "-- testing '$name' --\n";
- readfile($name);
-}
+foreach($names_arr as $key => $value) {
+ echo "\n-- Filename: $key --\n";
+ readfile($value);
+};
-echo "\n*** Done ***\n";
?>
+===Done===
--EXPECTF--
*** Testing readfile() : variation ***
--- testing '-1' --
+
+-- Filename: -1 --
Warning: readfile(-1): failed to open stream: No such file or directory in %s on line %d
--- testing '1' --
+
+-- Filename: TRUE --
Warning: readfile(1): failed to open stream: No such file or directory in %s on line %d
--- testing '' --
--- testing '' --
--- testing '' --
--- testing ' ' --
+
+-- Filename: FALSE --
+
+Warning: readfile(): Filename cannot be empty in %s on line %d
+
+-- Filename: NULL --
+
+Warning: readfile(): Filename cannot be empty in %s on line %d
+
+-- Filename: "" --
+
+Warning: readfile(): Filename cannot be empty in %s on line %d
+
+-- Filename: " " --
Warning: readfile( ): failed to open stream: Permission denied in %s on line %d
--- testing '%s' --
--- testing 'Array' --
+
+-- Filename: \0 --
+
+Warning: readfile(): Filename cannot be empty in %s on line %d
+
+-- Filename: array() --
Warning: readfile() expects parameter 1 to be string, array given in %s on line %d
--- testing '/no/such/file/dir' --
+
+-- Filename: /no/such/file/dir --
Warning: readfile(/no/such/file/dir): failed to open stream: No such file or directory in %s on line %d
--- testing 'php/php' --
-Warning: readfile(php/php): failed to open stream: No such file or directory in %s on line %d
+-- Filename: php/php --
-*** Done ***
\ No newline at end of file
+Warning: readfile(php/php): failed to open stream: No such file or directory in %s on line %d
+===Done===
\ No newline at end of file