Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <?php
  2.  
  3. class A {
  4. const TEST = "foo";
  5.  
  6. public static $variable;
  7.  
  8. public static $variable2;
  9.  
  10. public static function setVar1($v)
  11. {
  12. static::setVariable($v);
  13. }
  14.  
  15. public static function setVar2($v)
  16. {
  17. self::setVariable($v);
  18. }
  19.  
  20. protected static function setVariable($v)
  21. {
  22. self::$variable = $v;
  23. }
  24.  
  25. public static function getConstant1()
  26. {
  27. return static::TEST;
  28. }
  29.  
  30. public static function getConstant2()
  31. {
  32. return self::TEST;
  33. }
  34. }
  35.  
  36. class B extends A
  37. {
  38. const TEST = "bar";
  39.  
  40. protected static function setVariable($v)
  41. {
  42. self::$variable2 = $v;
  43. }
  44. }
  45.  
  46. // ----
  47. echo "A\n";
  48. echo "getConstant1: ".A::getConstant1() . "\n";
  49. echo "getConstant2: ".A::getConstant2() . "\n";
  50. A::setVar1("foo");
  51. echo "setVar1(foo): variable: '".A::$variable . "', variable2: '".A::$variable2 . "'\n";
  52. A::setVar2("bar");
  53. echo "setVar2(bar): variable: '".A::$variable . "', variable2: '".A::$variable2 . "'\n";
  54.  
  55. echo "\nB\n";
  56. echo "getConstant1: ".B::getConstant1() . "\n";
  57. echo "getConstant2: ".B::getConstant2() . "\n";
  58. B::setVar1("foo");
  59. echo "setVar1(foo): variable: '".B::$variable . "', variable2: '".B::$variable2 . "'\n";
  60. B::setVar2("bar");
  61. echo "setVar2(bar): variable: '".B::$variable . "', variable2: '".B::$variable2 . "'\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement