Created
June 5, 2012 20:49
-
-
Save jasonrhodes/2877783 to your computer and use it in GitHub Desktop.
Self vs Static in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A | |
{ | |
public static $var = "I'm set in A!<br>"; | |
public static function getStatic() { | |
echo static::$var; | |
} | |
public static function getSelf() { | |
echo self::$var; | |
} | |
} | |
class B extends A | |
{ | |
public static $var = "I'm set in B!<br>"; | |
} | |
B::getSelf(); // I'm set in A! | |
B::getStatic(); // I'm set in B! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment