-
-
Save stephan-v/0150b2b2f14fc3f2c6d13b7496a65e3a to your computer and use it in GitHub Desktop.
Self vs Static in PHP
This file contains hidden or 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