有人可以解释一下为什么当我这样做时print_r($student->getStudents())
我只得到数组的大小并is_array
返回false。
这是我的输出
Jane Doe enrolled at Aviation High School
All students:
Nope!3
<?php
class Student{
public $name;
public $students = array('Jason', 'Joe');
public function __construct($name){
$this->name = $name;
$this->students = array_push($this->students, $name);
}
public function lastName(){
return "Doe";
}
public function getStudents(){
return $this->students;
}
}
class School{
public $name;
public function __construct($name){
$this->name = $name;
}
}
class Admin{
public function enroll(Student $student,School $school){
echo $student->name.' '.$student->lastName().' enrolled at '. $school->name;
echo '<br />All students:<br />';
echo is_array($student->getStudents()) ? 'Yeah!':'Nope!' ;
}
}
$student = new Student("Jane");
$school = new School("Aviation High School");
$admin = new Admin();
$admin->enroll($student, $school);