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--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,
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  $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  }
45  else {
46     echo "Failed to write data to: $names_arr[$i]\n";
47  }
48}
49
50echo "\n*** Done ***\n";
51?>
52--EXPECTF--
53*** Testing file_put_contents() : usage variation ***
54-- Iteration 0 --
559 bytes written to: -1
56-- Iteration 1 --
579 bytes written to: 1
58-- Iteration 2 --
59
60Warning: file_put_contents(): Filename cannot be empty in %s on line %d
61Failed to write data to:
62-- Iteration 3 --
63
64Warning: file_put_contents(): Filename cannot be empty in %s on line %d
65Failed to write data to:
66-- Iteration 4 --
67
68Warning: file_put_contents(): Filename cannot be empty in %s on line %d
69Failed to write data to:
70-- Iteration 5 --
719 bytes written to:
72-- Iteration 6 --
73
74Warning: file_put_contents() expects parameter 1 to be a valid path, string given in %s on line %d
75Failed to write data to: �
76-- Iteration 7 --
77
78Warning: file_put_contents() expects parameter 1 to be a valid path, array given in %s on line %d
79
80Notice: Array to string conversion in %s on line %d
81Failed to write data to: Array
82-- Iteration 8 --
83
84Warning: file_put_contents(%sdir): failed to open stream: %s in %s on line %d
85Failed to write data to: %sdir
86-- Iteration 9 --
87
88Warning: file_put_contents(%sphp): failed to open stream: %s in %s on line %d
89Failed to write data to: %sphp
90
91*** Done ***
92
93