Annotation of embedaddon/php/ext/standard/tests/array/key_exists_variation2.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test function key_exists() by calling it with its expected arguments
3: --CREDITS--
4: Francesco Fullone ff@ideato.it
5: #PHPTestFest Cesena Italia on 2009-06-20
6: --FILE--
7: <?php
8: echo "*** test key_exists() by using mixed type of arrays ***\n";
9:
10: // there is not a index = 0 element
11: $a = array(1 => 'bar', 'foo' => 'baz');
12: var_dump(key_exists(0, $a));
13:
14: echo "integer\n";
15: // 1 has index = 0
16: $b = array(1, 'foo' => 'baz');
17: var_dump(key_exists(0, $b));
18:
19: // 42 has index = 0, netherless its position is the latest
20: $c = array('foo' => 'baz', 42);
21: var_dump(key_exists(0, $c));
22:
23: echo "string\n";
24: // 'bar' has index = 0, netherless it is a string
25: $d = array('bar', 'foo' => 'baz');
26: var_dump(key_exists(0, $d));
27:
28: // 'baz' has index = 0, netherless its position is the latest
29: $e = array('foo' => 'baz', 'baz');
30: var_dump(key_exists(0, $e));
31:
32: echo "obj\n";
33: class ObjectA
34: {
35: public $foo = 'bar';
36: }
37:
38: $obj = new ObjectA();
39:
40: // object has index = 0, netherless its position is the latest
41: $f = array('foo' => 'baz', $obj);
42: var_dump(key_exists(0, $f));
43:
44: // object has index = 0, netherless its position is the first
45: $g = array($obj, 'foo' => 'baz');
46: var_dump(key_exists(0, $g));
47:
48: echo "stream resource\n";
49: // stream resource has index = 0, netherless its position is the first
50: $st = fopen('php://memory', '+r');
51: $h = array($st, 'foo' => 'baz');
52: var_dump(key_exists(0, $h));
53:
54: // stream resource has index = 0, netherless its position is the latest
55: $i = array('foo' => 'baz', $st);
56: var_dump(key_exists(0, $i));
57:
58: --EXPECTF--
59: *** test key_exists() by using mixed type of arrays ***
60: bool(false)
61: integer
62: bool(true)
63: bool(true)
64: string
65: bool(true)
66: bool(true)
67: obj
68: bool(true)
69: bool(true)
70: stream resource
71: bool(true)
72: bool(true)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>