@@ -18,34 +18,28 @@ mkdir($dir);
1818chdir ($ dir );
1919
2020/* An array of filenames */
21- $ names_arr = array (
22- -1 ,
23- TRUE ,
24- FALSE ,
21+ $ names = [
22+ /* Invalid args */
23+ '-1 ' ,
2524 "" ,
2625 " " ,
27- //this one also generates a java message rather than our own so we don't replicate php message
2826 "\0" ,
29- array (),
30-
31- //the next 2 generate java messages so we don't replicate the php messages
27+ /* prefix with path separator of a non existing directory*/
3228 "/no/such/file/dir " ,
33- "php/php "
34-
35- );
29+ "php/php " ,
30+ ];
3631
37- for ( $ i =0 ; $ i <count ($ names_arr ); $ i ++ ) {
38- echo "-- Iteration $ i -- \n" ;
32+ foreach ($ names as $ name ) {
3933 try {
40- $ res = file_put_contents ($ names_arr [ $ i ] , "Some data " );
34+ $ res = file_put_contents ($ name , "Some data " );
4135 if ($ res !== false && $ res != null ) {
42- echo "$ res bytes written to: ' $ names_arr [ $ i ] ' \n" ;
43- unlink ($ names_arr [ $ i ] );
36+ echo "$ res bytes written to: ' $ name ' \n" ;
37+ unlink ($ name );
4438 } else {
45- echo "Failed to write data to: ' $ names_arr [ $ i ] ' \n" ;
39+ echo "Failed to write data to: ' $ name ' \n" ;
4640 }
47- } catch (\TypeError | \ ValueError $ e ) {
48- echo get_class ( $ e ) . ': ' . $ e ->getMessage (), "\n" ;
41+ } catch (\Throwable $ e ) {
42+ echo $ e ::class, ': ' , $ e ->getMessage (), "\n" ;
4943 }
5044}
5145
@@ -59,25 +53,13 @@ rmdir($dir);
5953?>
6054--EXPECTF--
6155*** Testing file_put_contents() : usage variation ***
62- -- Iteration 0 --
63569 bytes written to: '-1'
64- -- Iteration 1 --
65- 9 bytes written to: '1'
66- -- Iteration 2 --
67- ValueError: Path must not be empty
68- -- Iteration 3 --
6957ValueError: Path must not be empty
70- -- Iteration 4 --
71589 bytes written to: ' '
72- -- Iteration 5 --
7359ValueError: file_put_contents(): Argument #1 ($filename) must not contain any null bytes
74- -- Iteration 6 --
75- TypeError: file_put_contents(): Argument #1 ($filename) must be of type string, array given
76- -- Iteration 7 --
7760
7861Warning: file_put_contents(%sdir): Failed to open stream: %s in %s on line %d
7962Failed to write data to: '%sir'
80- -- Iteration 8 --
8163
8264Warning: file_put_contents(%sphp): Failed to open stream: %s in %s on line %d
8365Failed to write data to: '%sphp'
0 commit comments