Created
January 27, 2019 20:02
-
-
Save evert/8e1d9b2d5a97c4e69712af802afba707 to your computer and use it in GitHub Desktop.
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 declare(strict_types=1); | |
class Player { | |
private $name; | |
function __construct(string $name) { | |
$this->name = $name; | |
} | |
function getName(): string { | |
return $this->name; | |
} | |
} | |
class Team { | |
private $players = []; | |
function addPlayer(Player $player) { | |
$this->players[] = $player; | |
} | |
function printPlayerNames() { | |
foreach($this->players as $player) { | |
echo $player->getName(), "\n"; | |
} | |
} | |
} | |
$team = new Team('red'); | |
$player = new Player('john'); | |
$team->addPlayer($player); | |
$team->printPlayerNames(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment