Annotation of embedaddon/php/ext/spl/tests/SplObjectStorage_getHash.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: SplObjectStorage::getHash implementation
3: --FILE--
4: <?php
5: $s = new SplObjectStorage();
6: $o1 = new Stdclass;
7: $o2 = new Stdclass;
8: $s[$o1] = "some_value\n";
9: echo $s->offsetGet($o1);
10:
11: class MySplObjectStorage extends SplObjectStorage {
12: public function getHash($obj) {
13: return 2;
14: }
15: }
16:
17: try {
18: $s1 = new MySplObjectStorage;
19: $s1[$o1] = "foo";
20: } catch(Exception $e) {
21: echo "caught\n";
22: }
23:
24: class MySplObjectStorage2 extends SplObjectStorage {
25: public function getHash($obj) {
26: throw new Exception("foo");
27: return "asd";
28: }
29: }
30:
31: try {
32: $s2 = new MySplObjectStorage2;
33: $s2[$o2] = "foo";
34: } catch(Exception $e) {
35: echo "caught\n";
36: }
37:
38: class MySplObjectStorage3 extends SplObjectStorage {
39: public function getHash($obj) {
40: return "asd";
41: }
42: }
43:
44: $s3 = new MySplObjectStorage3;
45: $s3[$o1] = $o1;
46: var_dump($s3[$o1]);
47: $s3[$o2] = $o2;
48:
49: var_dump($s3[$o1] === $s3[$o2]);
50:
51: ?>
52: ===DONE===
53: --EXPECT--
54: some_value
55: caught
56: caught
57: object(stdClass)#2 (0) {
58: }
59: bool(true)
60: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>