summaryrefslogtreecommitdiff
path: root/Zend/tests/type_declarations/typed_properties_068.phpt
blob: 38597559cf045b5e8bb1aed69060db45e7779ebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--TEST--
Test typed static property by ref
--FILE--
<?php
function &ref($a = null) {
    static $f;
    if ($a !== null) $f = function &() use (&$a) { return $a; };
    return $f();
}

class Foo {
    public static int $i;
    public static string $s = "x";
}

Foo::$i = &ref(5);
var_dump(Foo::$i);

$i = &Foo::$i;
$i = 2;
var_dump($i, Foo::$i);

$i = "3";
var_dump($i, Foo::$i);

Foo::$i = "4";
var_dump($i, Foo::$i);

try {
    $i = null;
} catch (TypeError $e) { print $e->getMessage()."\n"; }
var_dump($i, Foo::$i);

try {
    Foo::$i = null;
} catch (TypeError $e) { print $e->getMessage()."\n"; }
var_dump($i, Foo::$i);

Foo::$s = &ref(5);
var_dump(Foo::$s, ref());

Foo::$i = &ref("0");
var_dump(Foo::$i, ref());

try {
    Foo::$i = &ref("x");
} catch (TypeError $e) { print $e->getMessage()."\n"; }
var_dump(Foo::$i, ref());

try {
    Foo::$i = &Foo::$s;
} catch (TypeError $e) { print $e->getMessage()."\n"; }
var_dump(Foo::$i, Foo::$s);

try {
    Foo::$s = &Foo::$i;
} catch (TypeError $e) { print $e->getMessage()."\n"; }
var_dump(Foo::$i, Foo::$s);

?>
--EXPECT--
int(5)
int(2)
int(2)
int(3)
int(3)
int(4)
int(4)
Cannot assign null to reference held by property Foo::$i of type int
int(4)
int(4)
Cannot assign null to property Foo::$i of type int
int(4)
int(4)
string(1) "5"
string(1) "5"
int(0)
int(0)
Cannot assign string to property Foo::$i of type int
int(0)
string(1) "x"
Reference with value of type string held by property Foo::$s of type string is not compatible with property Foo::$i of type int
int(0)
string(1) "5"
Reference with value of type int held by property Foo::$i of type int is not compatible with property Foo::$s of type string
int(0)
string(1) "5"