【发布时间】:2016-06-07 00:17:32
【问题描述】:
关于 php 对象的非常快速的问题。所以这里是代码:
<?php
class Person {
public $isAlive = true;
public $firstname, $lastname, $age;
public function __construct($firstname, $lastname, $age) {
$this->firstname = $firstname;
$this->lastname = $lastname;
$this->age = $age;
}
}
$teacher = new Person("boring", "12345", "boring");
echo $teacher->isAlive;
$student = new Person("Phil", "Kroupoderov", "20");
echo $student->age;
?>
我的年龄应该显示为 20,但由于某种原因显示为 120。为什么有一个 1 以及如何摆脱它??????
【问题讨论】:
-
true在 PHP 输出时表示为整数。所以echo $teacher->isAlive;会打印1,它会在您打印年龄之前出现。