Created
October 18, 2017 21:42
-
-
Save VictorFursa/58e0d3f88a82cfab2680950e5757b38d to your computer and use it in GitHub Desktop.
static and self
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 | |
{ | |
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