1--TEST--
2Test fileperms() & chmod() functions: usage variation - misc. perms
3--SKIPIF--
4<?php
5if (substr(PHP_OS, 0, 3) == 'WIN') {
6    die('skip Not on Windows');
7}
8require __DIR__ . '/../skipif_root.inc';
9?>
10--FILE--
11<?php
12/*
13  Prototype: int fileperms ( string $filename );
14  Description: Returns the permissions on the file, or FALSE in case of an error
15
16  Prototype: bool chmod ( string $filename, int $mode );
17  Description: Attempts to change the mode of the file specified by
18               filename to that given in mode
19*/
20
21/* Testing with miscellaneous Permission */
22
23echo "*** Testing fileperms() & chmod() : usage variations ***\n";
24
25$file_name = __DIR__."/006_variation2.tmp";
26$file_handle = fopen($file_name, "w");
27fclose($file_handle);
28$dir_name = __DIR__."/006_variation2";
29mkdir($dir_name);
30
31echo "\n*** Testing fileperms(), chmod() with miscellaneous permissions ***\n";
32$perms_array = array(
33  /* testing sticky bit */
34  07777,
35  00000,
36  01000,
37  011111,
38  /* negative  values as permission */
39  -0777, // permissions will be given as 2's complement form of -0777
40  -07777, // permissions will be given as 2's complement form of -07777
41
42  /* decimal values as permission  */
43  777, // permissions will be given as octal equivalent value of 777
44  7777, // permissions will be given as octal equivalent value of 7777
45  -7777, // permissions are given as 2's complement of octal equivalent of 7777
46
47  /* hex value as permission */
48  0x777, // permissions will be given as ocatal equivalent value of 0x777
49  0x7777,
50
51  /* strings notation of permission,  wont work properly */
52  "r+w",
53  "r+w+x",
54  "u+rwx",
55  "u+rwx, g+rw, o+wx"
56);
57
58$count = 1;
59foreach($perms_array as $permission) {
60  echo "-- Iteration $count --\n";
61  var_dump( chmod($file_name, $permission) );
62  printf("%o", fileperms($file_name) );
63  echo "\n";
64  clearstatcache();
65
66  var_dump( chmod($dir_name, $permission) );
67  printf("%o", fileperms($dir_name) );
68  echo "\n";
69  clearstatcache();
70  $count++;
71}
72echo "*** Done ***\n";
73?>
74--CLEAN--
75<?php
76chmod(__DIR__."/006_variation2.tmp", 0777);
77chmod(__DIR__."/006_variation2", 0777);
78unlink(__DIR__."/006_variation2.tmp");
79rmdir(__DIR__."/006_variation2");
80?>
81--EXPECTF--
82*** Testing fileperms() & chmod() : usage variations ***
83
84*** Testing fileperms(), chmod() with miscellaneous permissions ***
85-- Iteration 1 --
86bool(true)
87107777
88bool(true)
8947777
90-- Iteration 2 --
91bool(true)
92100000
93bool(true)
9440000
95-- Iteration 3 --
96bool(true)
97101000
98bool(true)
9941000
100-- Iteration 4 --
101bool(true)
102101111
103bool(true)
10441111
105-- Iteration 5 --
106bool(true)
107107001
108bool(true)
10947001
110-- Iteration 6 --
111bool(true)
112100001
113bool(true)
11440001
115-- Iteration 7 --
116bool(true)
117101411
118bool(true)
11941411
120-- Iteration 8 --
121bool(true)
122107141
123bool(true)
12447141
125-- Iteration 9 --
126bool(true)
127100637
128bool(true)
12940637
130-- Iteration 10 --
131bool(true)
132103567
133bool(true)
13443567
135-- Iteration 11 --
136bool(true)
137103567
138bool(true)
13943567
140-- Iteration 12 --
141
142Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
143NULL
144103567
145
146Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
147NULL
14843567
149-- Iteration 13 --
150
151Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
152NULL
153103567
154
155Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
156NULL
15743567
158-- Iteration 14 --
159
160Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
161NULL
162103567
163
164Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
165NULL
16643567
167-- Iteration 15 --
168
169Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
170NULL
171103567
172
173Warning: chmod() expects parameter 2 to be int, string given in %s on line %d
174NULL
17543567
176*** Done ***
177