bug63462.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. Test script to verify that magic methods should be called only once when accessing an unset property.
  3. --CREDITS--
  4. Marco Pivetta <ocramius@gmail.com>
  5. --FILE--
  6. <?php
  7. class Test {
  8. public $publicProperty;
  9. protected $protectedProperty;
  10. private $privateProperty;
  11. public function __construct() {
  12. unset(
  13. $this->publicProperty,
  14. $this->protectedProperty,
  15. $this->privateProperty
  16. );
  17. }
  18. function __get($name) {
  19. echo '__get ' . $name . "\n";
  20. return $this->$name;
  21. }
  22. function __set($name, $value) {
  23. echo '__set ' . $name . "\n";
  24. $this->$name = $value;
  25. }
  26. function __isset($name) {
  27. echo '__isset ' . $name . "\n";
  28. return isset($this->$name);
  29. }
  30. }
  31. $test = new Test();
  32. $test->nonExisting;
  33. $test->publicProperty;
  34. $test->protectedProperty;
  35. $test->privateProperty;
  36. isset($test->nonExisting);
  37. isset($test->publicProperty);
  38. isset($test->protectedProperty);
  39. isset($test->privateProperty);
  40. $test->nonExisting = 'value';
  41. $test->publicProperty = 'value';
  42. $test->protectedProperty = 'value';
  43. $test->privateProperty = 'value';
  44. ?>
  45. --EXPECTF--
  46. __get nonExisting
  47. Warning: Undefined property: Test::$nonExisting in %s on line %d
  48. __get publicProperty
  49. Warning: Undefined property: Test::$publicProperty in %s on line %d
  50. __get protectedProperty
  51. Warning: Undefined property: Test::$protectedProperty in %s on line %d
  52. __get privateProperty
  53. Warning: Undefined property: Test::$privateProperty in %s on line %d
  54. __isset nonExisting
  55. __isset publicProperty
  56. __isset protectedProperty
  57. __isset privateProperty
  58. __set nonExisting
  59. __set publicProperty
  60. __set protectedProperty
  61. __set privateProperty