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