如果需要,可以通过构造函数将参数传递给类。
class Test {
public function __construct($echo) {
echo $echo;
}
}
$test = new Test('hello'); // Echos "hello"
有没有办法将参数传递给__destruct
?
class Test {
public function __construct($echo) {
echo $echo;
}
public function __destruct($string) { // Is this possible?
// Do something with this string
}
}
答案 0 :(得分:1)
答案 1 :(得分:1)
这是不可能的。 但您可以使用如下的实例字段:
class Test {
var $value;
public function __construct($echo) {
this->value = $echo;
}
public function __destruct() {
echo $this->value;
}
}