Created
March 24, 2015 02:15
-
-
Save nrjones8/646d7c632b26076c7ce8 to your computer and use it in GitHub Desktop.
PHP's abstract static functions
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 | |
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