Created
January 9, 2014 17:03
-
-
Save erjiang/8337794 to your computer and use it in GitHub Desktop.
PHP inheritance and get_class
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 BigClass { | |
function whatIsThis() { | |
echo __METHOD__ . ": " . get_class() . "\n"; | |
} | |
function whatIsThisNow() { | |
echo __METHOD__ . ": " . get_class($this) . "\n"; | |
} | |
} | |
class LittleClass extends BigClass { | |
} | |
$bc = new BigClass(); | |
$lc = new LittleClass(); | |
$bc->whatIsThis(); | |
$bc->whatIsThisNow(); | |
$lc->whatIsThis(); | |
$lc->whatIsThisNow(); | |
/* output: | |
BigClass::whatIsThis: BigClass | |
BigClass::whatIsThisNow: BigClass | |
BigClass::whatIsThis: BigClass | |
BigClass::whatIsThisNow: LittleClass | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment