【发布时间】:2014-02-09 23:26:20
【问题描述】:
我正在 codecademy 上 PHP 课程,但我被困在了最后。 我真的很感激这里的一些帮助。 从我得到的,我认为我完成了我的任务。 这是它的确切说法:
公共属性 $firstname、$lastname 和 $age 应该得到一个 通过构造函数获取值。更改代码,所以 $teacher's: $firstname 是 "无聊", $lastname 是 "12345", $age 是 12345 添加你的 $firstname, $lastname 和 $age 到 $student。回显 $student 的 $age。
我不断收到消息:
糟糕,再试一次。嘿,您是否忘记将我的名字作为属性添加到对象中? :-P
<?php
class Person {
public $isAlive = true;
public $firstname;
public $lastname;
public $age;
// public function _contstruct You can do it!
public function __construct($firstname, $lastname, $age) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
$teacher = new Person("Boring","12345",12345);
$student = new Person("Stud","Nenti",19);
echo $teacher->isAlive;
echo $student->age;
?>
【问题讨论】:
-
我看不出你上面提供的代码有什么问题。