ReflectionProperty_hasDefaultValue.phpt 1.4 KB

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