Created
March 31, 2017 22:54
-
-
Save acapps/dd55d59a46966a8f71f34dd920863158 to your computer and use it in GitHub Desktop.
This file contains 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 Base | |
*/ | |
Class Base { | |
/** | |
* @param $name | |
* @return string | |
*/ | |
public static function hello($name) { | |
return sprintf('Hello, %s!', $name); | |
} | |
} | |
/** | |
* Class Extended | |
*/ | |
Class Extended extends Base { | |
/** | |
* @param $name string | |
* @return string | |
*/ | |
public static function hello($name = null) { | |
if (null === $name) { | |
$name = 'World'; | |
} | |
return parent::hello($name); | |
} | |
} | |
/** | |
* Class ExtendedLegacy | |
*/ | |
Class ExtendedLegacy extends Base { | |
/** | |
* @param $name string | |
* @return string | |
*/ | |
public static function hello($name = null) { | |
if (null === $name) { | |
$name = 'Universe'; | |
} | |
return sprintf('Hello, %s!', ucwords($name)); | |
} | |
} | |
$emptyName = null; | |
$name = 'bob'; | |
echo '=== Base ===' . PHP_EOL; | |
echo Base::hello($emptyName) . PHP_EOL; | |
echo Base::hello($name) . PHP_EOL; | |
echo '=== Extended ===' . PHP_EOL; | |
echo Extended::hello($emptyName) . PHP_EOL; | |
echo Extended::hello($name) . PHP_EOL; | |
echo '=== ExtendedLegacy ===' . PHP_EOL; | |
echo ExtendedLegacy::hello($emptyName) . PHP_EOL; | |
echo ExtendedLegacy::hello($name) . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following example outputs:
=== Base ===
Hello, !
Hello, bob!
=== Extended ===
Hello, World!
Hello, bob!
=== ExtendedLegacy ===
Hello, Universe!
Hello, Bob!