0
我有一个PHP类,我想它有它,所以变量只是一个布尔值?在一个PHP类中,我该如何使变量成为特定类型?
class TestClass {
private $isTrue;
public function __construct ($isTrue) {
$this -> isTrue = $isTrue;
}
public function getIsTrue ($isTrue) {
return $this -> isTrue;
}
public function setIsTrue ($isTrue) {
$this -> isTrue = $isTrue;
}
}
或者是我需要在setter和构造函数中这样做吗?
class TestClass {
private $isTrue;
public function __construct ($isTrue) {
$this -> isTrue = (bool)$isTrue;
}
public function getIsTrue ($isTrue) {
return $this -> isTrue;
}
public function setIsTrue ($isTrue) {
$this -> isTrue = (bool)$isTrue;
}
}
难道这就是我在做本身cond代码块? – kingcobra1986
变量类型是基于变量用法在运行时定义的PHP,因此不能单独定义。 –