Created
November 11, 2020 10:32
-
-
Save phpfiddle/f7c30f308d926546883f1417d32469d6 to your computer and use it in GitHub Desktop.
[ Posted by Itw Team ] php static vs self method
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 House { | |
public static function label() { | |
return "House"; | |
} | |
public function getChildLabel() { | |
return static::label(); | |
} | |
public function getParentLabelIgnoreChildLabel() { | |
return self::label(); | |
} | |
} | |
class Bungalow extends House{ | |
public static function label() { | |
return "Bungalow"; | |
} | |
} | |
$myHouse = new Bungalow(); | |
echo $myHouse->getChildLabel(); | |
echo $myHouse->getParentLabelIgnoreChildLabel(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment