这行代码:
echo "<strong> {$this->author->last} {$this->date->shortYear()}</strong> ...";
给我这个错误:
Fatal error: Call to undefined method Date::shortYear() in /f5/debate/public/libs/Card.php on line 22
即使在 Date.php 中(包含在 Card.php 中):
class Date {
public $day;
public $month;
public $year;
public function shortYear() {
return substr($this->year, -2);
}
}
最佳答案
您正在实例化错误的 Date
类。您可以使用 PHP 的 get_class_methods()
函数来确认哪些方法可用。
关于php - "Call to undefined method"- 但我知道它存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3225812/