1--TEST-- 2Test file_put_contents() function : usage variation - obscure filenames 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if(substr(PHP_OS, 0, 3) == "WIN") 8 die("skip Not for Windows"); 9?> 10--CONFLICTS-- 11obscure_filename 12--FILE-- 13<?php 14echo "*** Testing file_put_contents() : usage variation ***\n"; 15 16$dir = __DIR__ . '/file_put_contents_variation8'; 17mkdir($dir); 18chdir($dir); 19 20/* An array of filenames */ 21$names_arr = array( 22 -1, 23 TRUE, 24 FALSE, 25 NULL, 26 "", 27 " ", 28 //this one also generates a java message rather than our own so we don't replicate php message 29 "\0", 30 array(), 31 32 //the next 2 generate java messages so we don't replicate the php messages 33 "/no/such/file/dir", 34 "php/php" 35 36); 37 38for( $i=0; $i<count($names_arr); $i++ ) { 39 echo "-- Iteration $i --\n"; 40 try { 41 $res = file_put_contents($names_arr[$i], "Some data"); 42 if ($res !== false && $res != null) { 43 echo "$res bytes written to: '$names_arr[$i]'\n"; 44 unlink($names_arr[$i]); 45 } else { 46 echo "Failed to write data to: '$names_arr[$i]'\n"; 47 } 48 } catch (\TypeError|\ValueError $e) { 49 echo get_class($e) . ': ' . $e->getMessage(), "\n"; 50 } 51} 52rmdir($dir); 53 54echo "\n*** Done ***\n"; 55?> 56--EXPECTF-- 57*** Testing file_put_contents() : usage variation *** 58-- Iteration 0 -- 599 bytes written to: '-1' 60-- Iteration 1 -- 619 bytes written to: '1' 62-- Iteration 2 -- 63ValueError: Path cannot be empty 64-- Iteration 3 -- 65ValueError: Path cannot be empty 66-- Iteration 4 -- 67ValueError: Path cannot be empty 68-- Iteration 5 -- 699 bytes written to: ' ' 70-- Iteration 6 -- 71ValueError: file_put_contents(): Argument #1 ($filename) must not contain any null bytes 72-- Iteration 7 -- 73TypeError: file_put_contents(): Argument #1 ($filename) must be of type string, array given 74-- Iteration 8 -- 75 76Warning: file_put_contents(%sdir): Failed to open stream: %s in %s on line %d 77Failed to write data to: '%sir' 78-- Iteration 9 -- 79 80Warning: file_put_contents(%sphp): Failed to open stream: %s in %s on line %d 81Failed to write data to: '%sphp' 82 83*** Done *** 84