Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class A {
- const TEST = "foo";
- public static $variable;
- public static $variable2;
- public static function setVar1($v)
- {
- static::setVariable($v);
- }
- public static function setVar2($v)
- {
- self::setVariable($v);
- }
- protected static function setVariable($v)
- {
- self::$variable = $v;
- }
- public static function getConstant1()
- {
- return static::TEST;
- }
- public static function getConstant2()
- {
- return self::TEST;
- }
- }
- class B extends A
- {
- const TEST = "bar";
- protected static function setVariable($v)
- {
- self::$variable2 = $v;
- }
- }
- // ----
- echo "A\n";
- echo "getConstant1: ".A::getConstant1() . "\n";
- echo "getConstant2: ".A::getConstant2() . "\n";
- A::setVar1("foo");
- echo "setVar1(foo): variable: '".A::$variable . "', variable2: '".A::$variable2 . "'\n";
- A::setVar2("bar");
- echo "setVar2(bar): variable: '".A::$variable . "', variable2: '".A::$variable2 . "'\n";
- echo "\nB\n";
- echo "getConstant1: ".B::getConstant1() . "\n";
- echo "getConstant2: ".B::getConstant2() . "\n";
- B::setVar1("foo");
- echo "setVar1(foo): variable: '".B::$variable . "', variable2: '".B::$variable2 . "'\n";
- B::setVar2("bar");
- echo "setVar2(bar): variable: '".B::$variable . "', variable2: '".B::$variable2 . "'\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement