Created
July 16, 2017 17:27
-
-
Save VictorFursa/b1f8acfcc24f41ed9cc73ac247ba0d43 to your computer and use it in GitHub Desktop.
WebbyLab
This file contains hidden or 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 Animal | |
{ | |
/** | |
* @var Animal|string $name | |
*/ | |
protected $name; | |
/** | |
* Animal constructor. | |
* @param string $name | |
*/ | |
public function __construct(string $name) | |
{ | |
return $this->name = $name; | |
} | |
abstract protected function getName(); | |
} |
This file contains hidden or 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 Cat extends Animal | |
{ | |
/** | |
* Cat constructor. | |
* @param string $name | |
*/ | |
public function __construct(string $name) | |
{ | |
return parent::__construct($name); | |
} | |
/** | |
* @return Animal|string | |
*/ | |
public function getName() | |
{ | |
return $this->name; | |
} | |
/** | |
* @return string | |
*/ | |
public function meow() | |
{ | |
return "Cat $this->name is saying meow"; | |
} | |
} | |
$cat = new Cat('garfield'); | |
echo $cat->getName(); | |
echo $cat->meow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment