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 "", 26 " ", 27 //this one also generates a java message rather than our own so we don't replicate php message 28 "\0", 29 array(), 30 31 //the next 2 generate java messages so we don't replicate the php messages 32 "/no/such/file/dir", 33 "php/php" 34 35); 36 37for( $i=0; $i<count($names_arr); $i++ ) { 38 echo "-- Iteration $i --\n"; 39 try { 40 $res = file_put_contents($names_arr[$i], "Some data"); 41 if ($res !== false && $res != null) { 42 echo "$res bytes written to: '$names_arr[$i]'\n"; 43 unlink($names_arr[$i]); 44 } else { 45 echo "Failed to write data to: '$names_arr[$i]'\n"; 46 } 47 } catch (\TypeError|\ValueError $e) { 48 echo get_class($e) . ': ' . $e->getMessage(), "\n"; 49 } 50} 51rmdir($dir); 52 53echo "\n*** Done ***\n"; 54?> 55--EXPECTF-- 56*** Testing file_put_contents() : usage variation *** 57-- Iteration 0 -- 589 bytes written to: '-1' 59-- Iteration 1 -- 609 bytes written to: '1' 61-- Iteration 2 -- 62ValueError: Path cannot be empty 63-- Iteration 3 -- 64ValueError: Path cannot be empty 65-- Iteration 4 -- 669 bytes written to: ' ' 67-- Iteration 5 -- 68ValueError: file_put_contents(): Argument #1 ($filename) must not contain any null bytes 69-- Iteration 6 -- 70TypeError: file_put_contents(): Argument #1 ($filename) must be of type string, array given 71-- Iteration 7 -- 72 73Warning: file_put_contents(%sdir): Failed to open stream: %s in %s on line %d 74Failed to write data to: '%sir' 75-- Iteration 8 -- 76 77Warning: file_put_contents(%sphp): Failed to open stream: %s in %s on line %d 78Failed to write data to: '%sphp' 79 80*** Done *** 81