为什么它显示未定义的变量。 未定义的变量:classRooms。 为什么我应该在类属性中使用var而不是仅在PHP中使用$。
class School {
var $teachersCount = 10;
var $classRooms =20;
function teachingHours(){
$teacherHours = array();
$teacherHours = $this->classRooms / $this->teachersCount;
foreach ($teacherHours as $key => $hours) {
$teacherHours = $teacherHours -$key;
echo $teacherHours.''.$key;
}
}
}
实例化学校课程
$school = new School();
echo $school-> classRooms;
echo"<br>";
echo $school -> teachersCount;
echo"<br>";
$school-> teachingHours();