DummyClass.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. class DummyClass
  3. {
  4. protected $checkMe = 1;
  5. protected $properties = array('checkMeToo' => 1);
  6. function __construct($checkMe = 1)
  7. {
  8. $this->checkMe = "constructed: ".$checkMe;
  9. }
  10. public function helloWorld() {
  11. return "hello";
  12. }
  13. public function goodByeWorld() {
  14. return "good bye";
  15. }
  16. protected function notYourBusinessWorld()
  17. {
  18. return "goAway";
  19. }
  20. public function getCheckMe() {
  21. return $this->checkMe;
  22. }
  23. public function getCheckMeToo() {
  24. return $this->checkMeToo;
  25. }
  26. public function call() {
  27. $this->targetMethod();
  28. return true;
  29. }
  30. public function targetMethod() {
  31. return true;
  32. }
  33. public function exceptionalMethod() {
  34. throw new Exception('Catch it!');
  35. }
  36. public function __set($name, $value) {
  37. if ($this->isMagical($name)) {
  38. $this->properties[$name] = $value;
  39. }
  40. }
  41. public function __get($name) {
  42. if ($this->__isset($name)) {
  43. return $this->properties[$name];
  44. }
  45. }
  46. public function __isset($name) {
  47. return $this->isMagical($name) && isset($this->properties[$name]);
  48. }
  49. private function isMagical($name) {
  50. $reflectionClass = new \ReflectionClass($this);
  51. return !$reflectionClass->hasProperty($name);
  52. }
  53. }