summaryrefslogtreecommitdiff
path: root/Zend/tests/type_declarations/typed_properties_039.phpt
blob: 47ae17f0ab82c46a09aaf1cd11e0c4cd3419dd2c (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
--TEST--
Repeated assign of a variable to mismatched property type must not succeed
--FILE--
<?php

class A {
        public int $foo;
}

class B {
        public A $foo;
}

$objs = [new A, new A];
$v = 1;

foreach ($objs as $obj) {
        $obj->foo = $v;
        $v = new A;
        $obj = new B;
        $obj->foo = $v;
}

var_dump($objs);

?>
--EXPECTF--
Fatal error: Uncaught TypeError: Cannot assign A to property A::$foo of type int in %s:%d
Stack trace:
#0 {main}
  thrown in %s on line %d