ReflectionProperty_getDefaultValue.phpt 1.7 KB

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