Skip to content

Instantly share code, notes, and snippets.

@allaniftrue
Created July 22, 2020 21:11
Show Gist options
  • Save allaniftrue/57037155cbedd992b0a123b50f238c9a to your computer and use it in GitHub Desktop.
Save allaniftrue/57037155cbedd992b0a123b50f238c9a to your computer and use it in GitHub Desktop.
<?php
interface Fowl
{
public function layEgg() : Egg;
}
class Egg
{
private $hatched;
private $type;
public function __construct(string $fowlType)
{
$this->type = $fowlType;
}
public function hatch() : ?Fowl
{
if ($this->hatched == true) {
throw new Exception('Already htached');
}
$this->hatched = true;
return new $this->type();
}
}
class Hen implements Fowl
{
public function layEgg() : Egg {
return new Egg('Hen');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment