002.phpt 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. Reflection properties are read only
  3. --FILE--
  4. <?php
  5. class ReflectionMethodEx extends ReflectionMethod
  6. {
  7. public $foo = "xyz";
  8. function __construct($c,$m)
  9. {
  10. echo __METHOD__ . "\n";
  11. parent::__construct($c,$m);
  12. }
  13. }
  14. $r = new ReflectionMethodEx('ReflectionMethodEx','getName');
  15. var_dump($r->class);
  16. var_dump($r->name);
  17. var_dump($r->foo);
  18. @var_dump($r->bar);
  19. try
  20. {
  21. $r->class = 'bullshit';
  22. }
  23. catch(ReflectionException $e)
  24. {
  25. echo $e->getMessage() . "\n";
  26. }
  27. try
  28. {
  29. $r->name = 'bullshit';
  30. }
  31. catch(ReflectionException $e)
  32. {
  33. echo $e->getMessage() . "\n";
  34. }
  35. $r->foo = 'bar';
  36. $r->bar = 'baz';
  37. var_dump($r->class);
  38. var_dump($r->name);
  39. var_dump($r->foo);
  40. var_dump($r->bar);
  41. ?>
  42. --EXPECT--
  43. ReflectionMethodEx::__construct
  44. string(26) "ReflectionFunctionAbstract"
  45. string(7) "getName"
  46. string(3) "xyz"
  47. NULL
  48. Cannot set read-only property ReflectionMethodEx::$class
  49. Cannot set read-only property ReflectionMethodEx::$name
  50. string(26) "ReflectionFunctionAbstract"
  51. string(7) "getName"
  52. string(3) "bar"
  53. string(3) "baz"