@ 2019-01-30T21:00:26Z <?php
class Student
{
private $name;
public function __construct(string $name)
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
}
class Secretary
{
private $students = [];
public function addStudent(Student $s): Secretary
{
array_push($this->students, $s);
return $this;
}
public function getStudents(): array
{
return $this->students;
}
}
$s = new Secretary();
$s->addStudent(new Student('Foo'));
var_dump($s->getStudents());
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.34 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 , 8.4.1 - 8.4.12 array(1) {
[0]=>
object(Student)#2 (1) {
["name":"Student":private]=>
string(3) "Foo"
}
}
Output for 4.3.0 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/CYVG1 on line 5
Process exited with code 255 . preferences:dark mode live preview ace vim emacs key bindings
129.91 ms | 407 KiB | 5 Q