Created
July 24, 2012 16:01
-
-
Save wizardishungry/3170861 to your computer and use it in GitHub Desktop.
Test my assumptions about how self:: works / late static binding
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 | |
/* | |
http://php.net/manual/en/language.oop5.late-static-bindings.php | |
*/ | |
class Adam { | |
const LORD='Adonai'; | |
public $knowledge = self::LORD; | |
public function getLord() { return self::LORD; } | |
public function getTrueLord() { return static::LORD; } | |
} | |
class Abel extends Adam { | |
const LORD='Yhwh'; | |
} | |
$a = new Abel(); | |
echo $a->knowledge, "\n"; | |
echo $a->getLord(), "\n"; | |
echo $a->getTrueLord(), "\n"; |
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
Yhwh | |
Adonai | |
Yhwh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment