1--TEST--
2Test flock() function: Error conditions
3--CONFLICTS--
4obscure_filename
5--FILE--
6<?php
7/*
8Description: PHP supports a portable way of locking complete files
9  in an advisory way
10*/
11
12echo "*** Testing error conditions ***\n";
13
14$file = preg_replace("~\.phpt?$~", '.tmp', __FILE__);
15$fp = fopen($file, "w");
16
17/* array of operations */
18$operations = array(
19  0,
20  LOCK_NB,
21  FALSE,
22  NULL,
23  array(1,2,3),
24  array(),
25  "string",
26  "",
27  "\0"
28);
29
30$i = 0;
31foreach($operations as $operation) {
32    echo "--- Iteration $i ---" . \PHP_EOL;
33    try {
34        var_dump(flock($fp, $operation));
35    } catch (\TypeError|\ValueError $e) {
36        echo $e->getMessage() . \PHP_EOL;
37    }
38    $i++;
39}
40
41
42/* Invalid arguments */
43$fp = fopen($file, "w");
44fclose($fp);
45try {
46    var_dump(flock($fp, LOCK_SH|LOCK_NB));
47} catch (TypeError $e) {
48    echo $e->getMessage(), "\n";
49}
50?>
51--CLEAN--
52<?php
53$file = __DIR__."/flock_error.tmp";
54unlink($file);
55?>
56--EXPECT--
57*** Testing error conditions ***
58--- Iteration 0 ---
59flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
60--- Iteration 1 ---
61flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
62--- Iteration 2 ---
63flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
64--- Iteration 3 ---
65flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
66--- Iteration 4 ---
67flock(): Argument #2 ($operation) must be of type int, array given
68--- Iteration 5 ---
69flock(): Argument #2 ($operation) must be of type int, array given
70--- Iteration 6 ---
71flock(): Argument #2 ($operation) must be of type int, string given
72--- Iteration 7 ---
73flock(): Argument #2 ($operation) must be of type int, string given
74--- Iteration 8 ---
75flock(): Argument #2 ($operation) must be of type int, string given
76flock(): supplied resource is not a valid stream resource
77