Last active
February 4, 2021 00:49
-
-
Save andrewmclagan/e5ebd7c4b068a4711e16271d6d46177e to your computer and use it in GitHub Desktop.
PHP - Interview Question
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 Cinema\Cast; | |
class CerseiLannister | |
{ | |
private string $name = 'Cersei Lannister'; | |
private JoannaLannister $child; | |
function __construct(JoannaLannister $joannaLannister) | |
{ | |
$this->child = $joannaLannister; | |
} | |
protected function name(): string | |
{ | |
return $this->name; | |
} | |
private function getCerseisChild(): JoannaLannister | |
{ | |
return $this->child; | |
} | |
} |
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 MyApp; | |
use Cinema\Cast\Families; | |
echo (new Families\TheLannisters)->getFamilyNames(); |
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 Cinema\Cast; | |
class Jaime | |
{ | |
private string $firstName = 'Jaime'; | |
private string $lastName = 'Lannister'; | |
function __construct(JoannaLannister $joannaLannister) | |
{ | |
$this->child = new JoannaLannister; | |
} | |
function getJaimiesName(): string | |
{ | |
return $this->firstName . ' ' . $this->lastName; | |
} | |
public function getChild(): JoannaLannister; | |
{ | |
return $this->child; | |
} | |
} |
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 Cinema\Cast; | |
class JoannaLannister | |
{ | |
private string $firstName = 'Joanna'; | |
private string $lastName = 'Lannister'; | |
function the_name() | |
{ | |
return $this->firstName . ' ' . $this->lastName; | |
} | |
} |
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 Cinema\Cast\Families; | |
class TheLannisters | |
{ | |
private array $members; | |
public function __construct() | |
{ | |
$this->members['jaime'] = new Jaime; | |
$this->members['joanna'] = new JoannaLannister; | |
$this->members['cersei'] = new CerseiLannister($this->members['joanna']); | |
} | |
function getFamilyNames():? string | |
{ | |
echo 'The Lannisters:'; | |
echo $this->members['jaime']->getJaimiesName() . "\n"; | |
echo $this->members['cersei']->name() . "\n"; | |
echo $this->members['cersei']->getCerseisChild()->getName(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment