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  array(1,2,3),
23  array(),
24  "string",
25  "",
26  "\0"
27);
28
29$i = 0;
30foreach($operations as $operation) {
31    echo "--- Iteration $i ---" . \PHP_EOL;
32    try {
33        var_dump(flock($fp, $operation));
34    } catch (\TypeError|\ValueError $e) {
35        echo $e->getMessage() . \PHP_EOL;
36    }
37    $i++;
38}
39
40
41/* Invalid arguments */
42$fp = fopen($file, "w");
43fclose($fp);
44try {
45    var_dump(flock($fp, LOCK_SH|LOCK_NB));
46} catch (TypeError $e) {
47    echo $e->getMessage(), "\n";
48}
49?>
50--CLEAN--
51<?php
52$file = __DIR__."/flock_error.tmp";
53unlink($file);
54?>
55--EXPECT--
56*** Testing error conditions ***
57--- Iteration 0 ---
58flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
59--- Iteration 1 ---
60flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
61--- Iteration 2 ---
62flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
63--- Iteration 3 ---
64flock(): Argument #2 ($operation) must be of type int, array given
65--- Iteration 4 ---
66flock(): Argument #2 ($operation) must be of type int, array given
67--- Iteration 5 ---
68flock(): Argument #2 ($operation) must be of type int, string given
69--- Iteration 6 ---
70flock(): Argument #2 ($operation) must be of type int, string given
71--- Iteration 7 ---
72flock(): Argument #2 ($operation) must be of type int, string given
73flock(): supplied resource is not a valid stream resource
74