Created
February 7, 2017 22:52
-
-
Save jake-yeg/2739349d71fe58f8739396229e516f81 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 | |
/* | |
Challenge 2: Implement AnswerInterface and get Question to echo "4". | |
*/ | |
class Question | |
{ | |
public function __construct(AnswerInterface $answer) | |
{ | |
echo "What is 2 + 2?\n"; | |
$answer = $answer->get()->the()->answer(); | |
if ($answer instanceof AnswerInterface) { | |
echo $answer . PHP_EOL; | |
} | |
} | |
} | |
interface AnswerInterface | |
{ | |
public function get(); | |
public function the(); | |
public function answer(); | |
} | |
// start editing here | |
class Answer implements AnswerInterface{ | |
private $theanswer; | |
public function __construct(){} | |
public function get(){ | |
$this->theanswer = 2; | |
return $this; | |
} | |
public function the(){ | |
$this->theanswer += 2; | |
return $this; | |
} | |
public function answer(){ | |
return $this; | |
} | |
public function __toString() { | |
return (string)$this->theanswer; | |
} | |
} | |
// end editing here | |
$answer = new Answer; | |
$question = new Question($answer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment