Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created November 11, 2020 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/f7c30f308d926546883f1417d32469d6 to your computer and use it in GitHub Desktop.
Save phpfiddle/f7c30f308d926546883f1417d32469d6 to your computer and use it in GitHub Desktop.
[ Posted by Itw Team ] php static vs self method
<?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