Last active
December 17, 2015 22:19
-
-
Save blizzarddreams/bf9675adadca77b56610 to your computer and use it in GitHub Desktop.
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 | |
| namespace Dog\App; | |
| use Dog\Dog; | |
| $beethoven = new Dog("Beethoven"); | |
| $beethoven->bark(); |
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 | |
| namespace Dog\Dog; | |
| class Dog | |
| { | |
| private $name; | |
| private static $dogCount = 0; | |
| function __construct($name = null) | |
| { | |
| $this->name = $name ?? "A Dog"; | |
| self::$dogCount += 1; | |
| } | |
| function __toString() | |
| { | |
| return "<Dog:$this->name>"; | |
| } | |
| function bark() | |
| { | |
| echo "$this->name goes bark!\n"; | |
| } | |
| static function dogCount() | |
| { | |
| return self::$dogCount; | |
| } | |
| static function allDogsBark(...$dogs) | |
| { | |
| foreach($dogs as $dog) | |
| { | |
| $dog->bark(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment