Skip to content

Instantly share code, notes, and snippets.

@nrjones8
Created March 24, 2015 02:15
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 nrjones8/646d7c632b26076c7ce8 to your computer and use it in GitHub Desktop.
Save nrjones8/646d7c632b26076c7ce8 to your computer and use it in GitHub Desktop.
PHP's abstract static functions
<?php
abstract class AbstractClass {
abstract protected static function Something();
}
class GoodExtender extends AbstractClass {
protected static function Something() {
echo "something!\n";
}
public function something_else() {
self::Something();
}
}
// This works just fine
$good = new GoodExtender();
$good->something_else();
// This causes a fatal error, comment it out to see the above example
// work
class BadExtender extends AbstractClass {
public function somthing_public() {
echo "I didn't implement Something(), so this shouldn't work";
}
}
$bad = new BadExtender();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment