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 14/* Prototype : int file_put_contents(string file, mixed data [, int flags [, resource context]]) 15 * Description: Write/Create a file with contents data and return the number of bytes written 16 * Source code: ext/standard/file.c 17 * Alias to functions: 18 */ 19 20echo "*** Testing file_put_contents() : usage variation ***\n"; 21 22$dir = __DIR__ . '/file_put_contents_variation8'; 23mkdir($dir); 24chdir($dir); 25 26/* An array of filenames */ 27$names_arr = array( 28 -1, 29 TRUE, 30 FALSE, 31 NULL, 32 "", 33 " ", 34 //this one also generates a java message rather than our own so we don't replicate php message 35 "\0", 36 array(), 37 38 //the next 2 generate java messages so we don't replicate the php messages 39 "/no/such/file/dir", 40 "php/php" 41 42); 43 44for( $i=0; $i<count($names_arr); $i++ ) { 45 echo "-- Iteration $i --\n"; 46 $res = file_put_contents($names_arr[$i], "Some data"); 47 if ($res !== false && $res != null) { 48 echo "$res bytes written to: $names_arr[$i]\n"; 49 unlink($names_arr[$i]); 50 } 51 else { 52 echo "Failed to write data to: $names_arr[$i]\n"; 53 } 54} 55rmdir($dir); 56 57echo "\n*** Done ***\n"; 58?> 59--EXPECTF-- 60*** Testing file_put_contents() : usage variation *** 61-- Iteration 0 -- 629 bytes written to: -1 63-- Iteration 1 -- 649 bytes written to: 1 65-- Iteration 2 -- 66 67Warning: file_put_contents(): Filename cannot be empty in %s on line %d 68Failed to write data to: 69-- Iteration 3 -- 70 71Warning: file_put_contents(): Filename cannot be empty in %s on line %d 72Failed to write data to: 73-- Iteration 4 -- 74 75Warning: file_put_contents(): Filename cannot be empty in %s on line %d 76Failed to write data to: 77-- Iteration 5 -- 789 bytes written to: 79-- Iteration 6 -- 80 81Warning: file_put_contents() expects parameter 1 to be a valid path, string given in %s on line %d 82Failed to write data to: 83-- Iteration 7 -- 84 85Warning: file_put_contents() expects parameter 1 to be a valid path, array given in %s on line %d 86 87Notice: Array to string conversion in %s on line %d 88Failed to write data to: Array 89-- Iteration 8 -- 90 91Warning: file_put_contents(%sdir): failed to open stream: %s in %s on line %d 92Failed to write data to: %sdir 93-- Iteration 9 -- 94 95Warning: file_put_contents(%sphp): failed to open stream: %s in %s on line %d 96Failed to write data to: %sphp 97 98*** Done *** 99