summaryrefslogtreecommitdiff
path: root/Zend/tests/type_declarations/typed_properties_074.phpt
blob: f13398d9d7bbf81620edbb39602bcd715aef43df (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
--TEST--
Typed property must be compatible when returned via &__get()
--FILE--
<?php

class Test {
    public $prop = "x";
    public int $val;

    public function &__get($name) {
        return $this->prop;
    }
}

$test = new Test;
$dummyRef = &$test->prop;
unset($test->val);
var_dump($test);
try {
    var_dump($test->val);
} catch (TypeError $e) { print $e->getMessage()."\n"; }
var_dump($test);

$test->prop = "y";
var_dump($test->prop);

?>
--EXPECT--
object(Test)#1 (1) {
  ["prop"]=>
  &string(1) "x"
  ["val"]=>
  uninitialized(int)
}
Cannot assign string to property Test::$val of type int
object(Test)#1 (1) {
  ["prop"]=>
  &string(1) "x"
  ["val"]=>
  uninitialized(int)
}
string(1) "y"