Skip to content

Instantly share code, notes, and snippets.

@stephan-v
Forked from jasonrhodes/self.static.php
Created December 8, 2016 15:38
Show Gist options
  • Save stephan-v/0150b2b2f14fc3f2c6d13b7496a65e3a to your computer and use it in GitHub Desktop.
Save stephan-v/0150b2b2f14fc3f2c6d13b7496a65e3a to your computer and use it in GitHub Desktop.
Self vs Static in PHP
<?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