1--TEST-- 2Assigning values to intersection types 3--FILE-- 4<?php 5 6interface X {} 7interface Y {} 8interface Z {} 9 10class TestParent implements X, Y {} 11class TestChild extends TestParent implements Z {} 12 13class A { 14 15 public X&Y&Z $prop; 16 17 public function method1(X&Y $a): X&Y&Z { 18 return new TestChild(); 19 } 20 public function method2(X $a): X&Y { 21 return new TestParent(); 22 } 23} 24 25$tp = new TestParent(); 26$tc = new TestChild(); 27 28$o = new A(); 29try { 30 $o->prop = $tp; 31} catch (TypeError $e) { 32 echo $e->getMessage(), \PHP_EOL; 33} 34 35$o->prop = $tc; 36 37$r = $o->method1($tp); 38var_dump($r); 39$r = $o->method2($tp); 40var_dump($r); 41$r = $o->method1($tc); 42var_dump($r); 43$r = $o->method2($tc); 44var_dump($r); 45 46 47?> 48--EXPECTF-- 49Cannot assign TestParent to property A::$prop of type X&Y&Z 50object(TestChild)#%d (0) { 51} 52object(TestParent)#%d (0) { 53} 54object(TestChild)#%d (0) { 55} 56object(TestParent)#%d (0) { 57} 58