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
14echo "*** Testing file_put_contents() : usage variation ***\n";
15
16$dir = __DIR__ . '/file_put_contents_variation8';
17mkdir($dir);
18chdir($dir);
19
20/* An array of filenames */
21$names_arr = array(
22  -1,
23  TRUE,
24  FALSE,
25  "",
26  " ",
27  //this one also generates a java message rather than our own so we don't replicate php message
28  "\0",
29  array(),
30
31  //the next 2 generate java messages so we don't replicate the php messages
32  "/no/such/file/dir",
33  "php/php"
34
35);
36
37for( $i=0; $i<count($names_arr); $i++ ) {
38    echo "-- Iteration $i --\n";
39    try {
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        } else {
45            echo "Failed to write data to: '$names_arr[$i]'\n";
46        }
47    } catch (\TypeError|\ValueError $e) {
48        echo get_class($e) . ': ' . $e->getMessage(), "\n";
49    }
50}
51
52echo "\n*** Done ***\n";
53?>
54--CLEAN--
55<?php
56$dir = __DIR__ . '/file_put_contents_variation8';
57// TODO Cleanup temp files?
58rmdir($dir);
59?>
60--EXPECTF--
61*** Testing file_put_contents() : usage variation ***
62-- Iteration 0 --
639 bytes written to: '-1'
64-- Iteration 1 --
659 bytes written to: '1'
66-- Iteration 2 --
67ValueError: Path cannot be empty
68-- Iteration 3 --
69ValueError: Path cannot be empty
70-- Iteration 4 --
719 bytes written to: ' '
72-- Iteration 5 --
73ValueError: file_put_contents(): Argument #1 ($filename) must not contain any null bytes
74-- Iteration 6 --
75TypeError: file_put_contents(): Argument #1 ($filename) must be of type string, array given
76-- Iteration 7 --
77
78Warning: file_put_contents(%sdir): Failed to open stream: %s in %s on line %d
79Failed to write data to: '%sir'
80-- Iteration 8 --
81
82Warning: file_put_contents(%sphp): Failed to open stream: %s in %s on line %d
83Failed to write data to: '%sphp'
84
85*** Done ***
86