1--TEST-- 2reflection: ReflectionProperty::hasDefaultValue 3--FILE-- 4<?php 5 6class TestClass 7{ 8 public $foo; 9 public $bar = 'baz'; 10 11 public static $static1; 12 public static $static2 = 1234; 13 14 public int $val1; 15 public int $val2 = 1234; 16 17 public ?int $nullable; 18 public ?int $nullable2 = null; 19} 20 21$property = new ReflectionProperty(TestClass::class, 'foo'); 22var_dump($property->hasDefaultValue()); 23 24$property = new ReflectionProperty(TestClass::class, 'bar'); 25var_dump($property->hasDefaultValue()); 26 27$property = new ReflectionProperty(TestClass::class, 'static1'); 28var_dump($property->hasDefaultValue()); 29 30$property = new ReflectionProperty(TestClass::class, 'static2'); 31var_dump($property->hasDefaultValue()); 32 33$property = new ReflectionProperty(TestClass::class, 'val1'); 34var_dump($property->hasDefaultValue()); 35 36$property = new ReflectionProperty(TestClass::class, 'val2'); 37var_dump($property->hasDefaultValue()); 38 39$property = new ReflectionProperty(TestClass::class, 'nullable'); 40var_dump($property->hasDefaultValue()); 41 42$property = new ReflectionProperty(TestClass::class, 'nullable2'); 43var_dump($property->hasDefaultValue()); 44 45$test = new TestClass; 46$test->dynamic = null; 47$property = new ReflectionProperty($test, 'dynamic'); 48var_dump($property->hasDefaultValue()); 49 50?> 51--EXPECT-- 52bool(true) 53bool(true) 54bool(true) 55bool(true) 56bool(false) 57bool(true) 58bool(false) 59bool(true) 60bool(false) 61