<?PHP
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;
}
}
}
class Answer implements AnswerInterface{
private $answer;
public function get(){
$this->answer = 2;
return $this;
}
public function the(){
$this->answer = $this->answer + 2;
return $this;
}
public function answer(){
return $this->answer;
}
}
interface AnswerInterface
{
public function get();
public function the();
public function answer();
}
// start editing here
// end editing here
$answer = new Answer;
$question = new Question($answer);
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
What is 2 + 2?
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Answer has a deprecated constructor in /in/iklTX on line 15
What is 2 + 2?