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 Only run on Windows");
9?>
10--FILE--
11<?php
12/* Prototype  : int file_put_contents(string file, mixed data [, int flags [, resource context]])
13 * Description: Write/Create a file with contents data and return the number of bytes written
14 * Source code: ext/standard/file.c
15 * Alias to functions:
16 */
17
18echo "*** Testing file_put_contents() : usage variation ***\n";
19
20/* An array of filenames */
21$names_arr = array(
22  "-1" => -1,
23  "TRUE" => TRUE,
24  "FALSE" => FALSE,
25  "NULL" => NULL,
26  "\"\"" => "",
27  "\" \"" => " ",
28  "\\0" => "\0",
29  "array()" => array(),
30
31  /* prefix with path separator of a non existing directory*/
32  "/no/such/file/dir" => "/no/such/file/dir",
33  "php/php"=> "php/php"
34
35);
36
37foreach($names_arr as $key =>$value) {
38      echo "\n-- Filename: $key --\n";
39      $res = file_put_contents($value, "Some data");
40  	  if ($res !== false && $res != null) {
41     	 echo "$res bytes written to: $value\n";
42     	 unlink($value);
43  	  } else {
44         echo "Failed to write data to: $key\n";
45      }
46};
47
48?>
49===Done===
50--EXPECTF--
51*** Testing file_put_contents() : usage variation ***
52
53-- Filename: -1 --
549 bytes written to: -1
55
56-- Filename: TRUE --
579 bytes written to: 1
58
59-- Filename: FALSE --
60
61Warning: file_put_contents(): Filename cannot be empty in %s on line %d
62Failed to write data to: FALSE
63
64-- Filename: NULL --
65
66Warning: file_put_contents(): Filename cannot be empty in %s on line %d
67Failed to write data to: NULL
68
69-- Filename: "" --
70
71Warning: file_put_contents(): Filename cannot be empty in %s on line %d
72Failed to write data to: ""
73
74-- Filename: " " --
75
76Warning: file_put_contents( ): failed to open stream: Permission denied in %s on line %d
77Failed to write data to: " "
78
79-- Filename: \0 --
80Failed to write data to: \0
81
82-- Filename: array() --
83
84Warning: file_put_contents() expects parameter 1 to be string, array given in %s on line %d
85Failed to write data to: array()
86
87-- Filename: /no/such/file/dir --
88
89Warning: file_put_contents(/no/such/file/dir): failed to open stream: %s in %s on line %d
90Failed to write data to: /no/such/file/dir
91
92-- Filename: php/php --
93
94Warning: file_put_contents(php/php): failed to open stream: %s in %s on line %d
95Failed to write data to: php/php
96===Done===
97