我试过$this->
但无法为$first_name and $last_name
变量赋值。如果不删除函数的静态特性并且不向变量插入静态特性,我该如何回显full_name()
?这是代码:
<?php
class User {
public $first_name;
public $last_name;
public function full_name() {
if(isset($this->first_name) && isset($this->last_name)) {
return $this->first_name . " " . $this->last_name;
} else {
return "No name!";
}
}
public static function verify() {
$this->first_name = "firstname";
$this->last_name = "last_name";
}
}
$user = new User();
User::verify();
echo $user->full_name()
?>