1--TEST-- 2ReflectionProperty::getSettableType() 3--FILE-- 4<?php 5 6class Test { 7 public $plainUntyped; 8 9 public int $plainTyped; 10 11 public $virtualReadOnlyUntyped { 12 get => 42; 13 } 14 15 public int $virtualReadOnlyTyped { 16 get => 42; 17 } 18 19 public int $asymmetricVirtualTyped { 20 get => 42; 21 set(int|string $value) {} 22 } 23 24 public $backedUntyped { 25 get => $this->backedUntyped; 26 set => $value; 27 } 28 29 public int $backedTyped { 30 get => $this->backedTyped; 31 set => $value; 32 } 33 34 public int $asymmetricBackedTyped { 35 get => $this->backedTyped; 36 set(int|string $value) => (int) $value; 37 } 38 39 public int $backedTypedGetOnly { 40 get => $this->backedTypedGetOnly; 41 } 42} 43 44$reflectionClass = new ReflectionClass(Test::class); 45foreach ($reflectionClass->getProperties() as $reflectionProperty) { 46 $type = $reflectionProperty->getSettableType(); 47 echo ($type ? $type : "NULL") . "\n"; 48} 49 50?> 51--EXPECT-- 52NULL 53int 54never 55never 56string|int 57NULL 58int 59string|int 60int 61