summaryrefslogtreecommitdiff
path: root/Zend/tests/type_declarations/typed_properties_108.phpt
blob: a2bd47988850c5758e28f7e9711165c7dc688066 (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
--TEST--
Variable assignment in catch must respect typed references
--FILE--
<?php

class Test {
    public int $i = 42;
    public string $s = "str";
}

$test = new Test;

$ref =& $test->i;
try {
    try {
        throw new Exception("ex");
    } catch (Exception $ref) {
        echo "Unreachable\n";
    }
} catch (TypeError $e) {
    var_dump($test->i);
    echo $e . "\n\n";
}

$ref =& $test->s;
try {
    try {
        throw new Exception("ex");
    } catch (Exception $ref) {
        echo "Unreachable\n";
    }
} catch (TypeError $e) {
    var_dump($test->s);
    echo $e . "\n\n";
}

?>
--EXPECTF--
int(42)
TypeError: Cannot assign Exception to reference held by property Test::$i of type int in %s:%d
Stack trace:
#0 {main}

string(3) "str"
TypeError: Cannot assign Exception to reference held by property Test::$s of type string in %s:%d
Stack trace:
#0 {main}