Implement WeakMap · php/php-src@d8c9902
1+--TEST--
2+WeakMap error conditions
3+--FILE--
4+<?php
5+6+$map = new WeakMap;
7+try {
8+$map[1] = 2;
9+} catch (TypeError $e) {
10+echo $e->getMessage(), "\n";
11+}
12+try {
13+var_dump($map[1]);
14+} catch (TypeError $e) {
15+echo $e->getMessage(), "\n";
16+}
17+try {
18+isset($map[1]);
19+} catch (TypeError $e) {
20+echo $e->getMessage(), "\n";
21+}
22+try {
23+ unset($map[1]);
24+} catch (TypeError $e) {
25+echo $e->getMessage(), "\n";
26+}
27+28+try {
29+$map[] = 1;
30+} catch (Error $e) {
31+echo $e->getMessage(), "\n";
32+}
33+try {
34+$map[][1] = 1;
35+} catch (Error $e) {
36+echo $e->getMessage(), "\n";
37+}
38+try {
39+var_dump($map[new stdClass]);
40+} catch (Error $e) {
41+echo $e->getMessage(), "\n";
42+}
43+44+try {
45+$map->prop = 1;
46+} catch (Error $e) {
47+echo $e->getMessage(), "\n";
48+}
49+try {
50+var_dump($map->prop);
51+} catch (Error $e) {
52+echo $e->getMessage(), "\n";
53+}
54+try {
55+$r =& $map->prop;
56+} catch (Error $e) {
57+echo $e->getMessage(), "\n";
58+}
59+try {
60+isset($map->prop);
61+} catch (Error $e) {
62+echo $e->getMessage(), "\n";
63+}
64+try {
65+ unset($map->prop);
66+} catch (Error $e) {
67+echo $e->getMessage(), "\n";
68+}
69+70+try {
71+serialize($map);
72+} catch (Exception $e) {
73+echo $e->getMessage(), "\n";
74+}
75+try {
76+unserialize('C:7:"WeakMap":0:{}');
77+} catch (Exception $e) {
78+echo $e->getMessage(), "\n";
79+}
80+81+?>
82+--EXPECT--
83+WeakMap key must be an object
84+WeakMap key must be an object
85+WeakMap key must be an object
86+WeakMap key must be an object
87+Cannot append to WeakMap
88+Cannot append to WeakMap
89+Object stdClass#2 not contained in WeakMap
90+WeakMap objects do not support properties
91+WeakMap objects do not support properties
92+WeakMap objects do not support property references
93+WeakMap objects do not support properties
94+WeakMap objects do not support properties
95+Serialization of 'WeakMap' is not allowed
96+Unserialization of 'WeakMap' is not allowed