1--TEST-- 2Intersection types in reflection 3--FILE-- 4<?php 5 6function dumpType(ReflectionIntersectionType $rt) { 7 echo "Type $rt:\n"; 8 echo "Allows null: " . json_encode($rt->allowsNull()) . "\n"; 9 foreach ($rt->getTypes() as $type) { 10 echo " Name: " . $type->getName() . "\n"; 11 echo " String: " . (string) $type . "\n"; 12 echo " Allows Null: " . json_encode($type->allowsNull()) . "\n"; 13 } 14} 15 16function test1(): X&Y&Z&Traversable&Countable { } 17 18class Test { 19 public X&Y&Countable $prop; 20} 21 22dumpType((new ReflectionFunction('test1'))->getReturnType()); 23 24$rc = new ReflectionClass(Test::class); 25$rp = $rc->getProperty('prop'); 26dumpType($rp->getType()); 27 28/* Force CE resolution of the property type */ 29 30interface y {} 31class x implements Y, Countable { 32 public function count(): int { return 0; } 33} 34$test = new Test; 35$test->prop = new x; 36 37$rp = $rc->getProperty('prop'); 38dumpType($rp->getType()); 39 40?> 41--EXPECT-- 42Type X&Y&Z&Traversable&Countable: 43Allows null: false 44 Name: X 45 String: X 46 Allows Null: false 47 Name: Y 48 String: Y 49 Allows Null: false 50 Name: Z 51 String: Z 52 Allows Null: false 53 Name: Traversable 54 String: Traversable 55 Allows Null: false 56 Name: Countable 57 String: Countable 58 Allows Null: false 59Type X&Y&Countable: 60Allows null: false 61 Name: X 62 String: X 63 Allows Null: false 64 Name: Y 65 String: Y 66 Allows Null: false 67 Name: Countable 68 String: Countable 69 Allows Null: false 70Type X&Y&Countable: 71Allows null: false 72 Name: X 73 String: X 74 Allows Null: false 75 Name: Y 76 String: Y 77 Allows Null: false 78 Name: Countable 79 String: Countable 80 Allows Null: false 81