Skip to content

Instantly share code, notes, and snippets.

@erjiang
Created January 9, 2014 17:03
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 erjiang/8337794 to your computer and use it in GitHub Desktop.
Save erjiang/8337794 to your computer and use it in GitHub Desktop.
PHP inheritance and get_class
<?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