1--TEST--
2Test typed static property by ref
3--FILE--
4<?php
5function &ref($a = null) {
6	static $f;
7	if ($a !== null) $f = function &() use (&$a) { return $a; };
8	return $f();
9}
10
11class Foo {
12	public static int $i;
13	public static string $s = "x";
14}
15
16Foo::$i = &ref(5);
17var_dump(Foo::$i);
18
19$i = &Foo::$i;
20$i = 2;
21var_dump($i, Foo::$i);
22
23$i = "3";
24var_dump($i, Foo::$i);
25
26Foo::$i = "4";
27var_dump($i, Foo::$i);
28
29try {
30	$i = null;
31} catch (TypeError $e) { print $e->getMessage()."\n"; }
32var_dump($i, Foo::$i);
33
34try {
35	Foo::$i = null;
36} catch (TypeError $e) { print $e->getMessage()."\n"; }
37var_dump($i, Foo::$i);
38
39Foo::$s = &ref(5);
40var_dump(Foo::$s, ref());
41
42Foo::$i = &ref("0");
43var_dump(Foo::$i, ref());
44
45try {
46	Foo::$i = &ref("x");
47} catch (TypeError $e) { print $e->getMessage()."\n"; }
48var_dump(Foo::$i, ref());
49
50try {
51	Foo::$i = &Foo::$s;
52} catch (TypeError $e) { print $e->getMessage()."\n"; }
53var_dump(Foo::$i, Foo::$s);
54
55try {
56	Foo::$s = &Foo::$i;
57} catch (TypeError $e) { print $e->getMessage()."\n"; }
58var_dump(Foo::$i, Foo::$s);
59
60?>
61--EXPECT--
62int(5)
63int(2)
64int(2)
65int(3)
66int(3)
67int(4)
68int(4)
69Cannot assign null to reference held by property Foo::$i of type int
70int(4)
71int(4)
72Typed property Foo::$i must be int, null used
73int(4)
74int(4)
75string(1) "5"
76string(1) "5"
77int(0)
78int(0)
79Typed property Foo::$i must be int, string used
80int(0)
81string(1) "x"
82Reference with value of type string held by property Foo::$s of type string is not compatible with property Foo::$i of type int
83int(0)
84string(1) "5"
85Reference with value of type int held by property Foo::$i of type int is not compatible with property Foo::$s of type string
86int(0)
87string(1) "5"
88