Skip to content

Instantly share code, notes, and snippets.

@evert
Created January 27, 2019 20:02
Show Gist options
  • Save evert/8e1d9b2d5a97c4e69712af802afba707 to your computer and use it in GitHub Desktop.
Save evert/8e1d9b2d5a97c4e69712af802afba707 to your computer and use it in GitHub Desktop.
<?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