1--TEST--
2User-space streams: stream_lock()
3--FILE--
4<?php
5class test_wrapper_base {
6    public $context;
7    public $mode;
8    function stream_open($path, $mode, $openedpath) {
9        return true;
10    }
11    function stream_eof() {
12        return false;
13    }
14}
15class test_wrapper extends test_wrapper_base {
16    function stream_lock($mode) {
17        $this->mode = $mode;
18    }
19}
20function test($name, $fd, $mode) {
21    echo "------ $name: -------\n";
22    flock($fd, $mode);
23    $data = stream_get_meta_data($fd);
24    var_dump($data['wrapper_data']->mode === $mode);
25}
26
27var_dump(stream_wrapper_register('test', 'test_wrapper'));
28var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));
29
30$fd = fopen("test://foo","r");
31$fd2 = fopen("test2://foo","r");
32
33test("stream_lock not implemented", $fd2, LOCK_EX);
34
35foreach(array("LOCK_SH","LOCK_EX","LOCK_UN") as $mode) {
36    test("fclock($mode)", $fd, constant($mode));
37    test("fclock($mode|LOCK_NB)", $fd, constant($mode)|LOCK_NB);
38}
39
40?>
41--EXPECTF--
42bool(true)
43bool(true)
44------ stream_lock not implemented: -------
45
46Warning: flock(): test_wrapper_base::stream_lock is not implemented! in %s
47bool(false)
48------ fclock(LOCK_SH): -------
49bool(true)
50------ fclock(LOCK_SH|LOCK_NB): -------
51bool(true)
52------ fclock(LOCK_EX): -------
53bool(true)
54------ fclock(LOCK_EX|LOCK_NB): -------
55bool(true)
56------ fclock(LOCK_UN): -------
57bool(true)
58------ fclock(LOCK_UN|LOCK_NB): -------
59bool(true)
60