Skip to content

Instantly share code, notes, and snippets.

@miyukki
Created December 10, 2013 07:27
Show Gist options
  • Save miyukki/7886940 to your computer and use it in GitHub Desktop.
Save miyukki/7886940 to your computer and use it in GitHub Desktop.
<?php
class A {
public static $name = "ClassA";
public static function printStatic() {
echo static::$name.PHP_EOL;
}
public static function printSelf() {
echo self::$name.PHP_EOL;
}
}
class B extends A {
public static $name = "ClassB";
}
class C extends A {
public static $name = "ClassC";
public static function printStatic() {
echo static::$name.PHP_EOL;
}
public static function printSelf() {
echo self::$name.PHP_EOL;
}
}
A::printStatic(); // ClassA
A::printSelf(); // ClassA
B::printStatic(); // ClassB
B::printSelf(); // ClassA
C::printStatic(); // ClassC
C::printSelf(); // ClassC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment