Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class Game
- {
- abstract function checkLevel();
- public function play()
- {
- $className = get_called_class();
- if ($this->checkLevel() === true) {
- return "{$className} can play";
- }
- return "{$className} can't play";
- }
- }
- class Mario extends Game
- {
- public function checkLevel()
- {
- return true;
- }
- }
- class Race extends Game
- {
- public function checkLevel()
- {
- return false;
- }
- }
- echo (new Mario)->play() . PHP_EOL;
- echo (new Race)->play() . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment