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--CONFLICTS--
11obscure_filename
12--FILE--
13<?php
14echo "*** Testing file_put_contents() : usage variation ***\n";
15
16/* An array of filenames */
17$names_arr = array(
18  "-1" => -1,
19  "TRUE" => TRUE,
20  "FALSE" => FALSE,
21  "NULL" => NULL,
22  "\"\"" => "",
23  "\" \"" => " ",
24  "\\0" => "\0",
25  "array()" => array(),
26
27  /* prefix with path separator of a non existing directory*/
28  "/no/such/file/dir" => "/no/such/file/dir",
29  "php/php"=> "php/php"
30
31);
32
33foreach($names_arr as $key =>$value) {
34    echo "\n-- Filename: $key --\n";
35    try {
36        $res = file_put_contents($value, "Some data");
37        if ($res !== false && $res != null) {
38            echo "$res bytes written to: '$value'\n";
39            unlink($value);
40        } else {
41            echo "Failed to write data to: $key\n";
42        }
43    } catch (\TypeError|\ValueError $e) {
44        echo get_class($e) . ': ' . $e->getMessage(), "\n";
45    }
46}
47
48?>
49--EXPECTF--
50*** Testing file_put_contents() : usage variation ***
51
52-- Filename: -1 --
539 bytes written to: '-1'
54
55-- Filename: TRUE --
569 bytes written to: '1'
57
58-- Filename: FALSE --
59ValueError: Path cannot be empty
60
61-- Filename: NULL --
62ValueError: Path cannot be empty
63
64-- Filename: "" --
65ValueError: Path cannot be empty
66
67-- Filename: " " --
68
69Warning: file_put_contents( ): Failed to open stream: Permission denied in %s on line %d
70Failed to write data to: " "
71
72-- Filename: \0 --
73ValueError: file_put_contents(): Argument #1 ($filename) must not contain any null bytes
74
75-- Filename: array() --
76TypeError: file_put_contents(): Argument #1 ($filename) must be of type string, array given
77
78-- Filename: /no/such/file/dir --
79
80Warning: file_put_contents(/no/such/file/dir): Failed to open stream: %s in %s on line %d
81Failed to write data to: /no/such/file/dir
82
83-- Filename: php/php --
84
85Warning: file_put_contents(php/php): Failed to open stream: %s in %s on line %d
86Failed to write data to: php/php
87