Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created October 18, 2017 21:42
Show Gist options
  • Save VictorFursa/58e0d3f88a82cfab2680950e5757b38d to your computer and use it in GitHub Desktop.
Save VictorFursa/58e0d3f88a82cfab2680950e5757b38d to your computer and use it in GitHub Desktop.
static and self
<?php
class A
{
static public $name = 'zir4onah';
static public function name()
{
return static::$name;
}
}
class B extends A
{
static public $name = 'qwe';
public function getName()
{
return B::name();
}
}
/** If STATIC:: return static::$name; i can return B::name = 'qwe' else if SELF:: return self::$name; return 'zir4onah' */
$a = new B();
$x = B::name(); // return qwe because static::$name;
$b = $a->getName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment