php - 为什么在PHP中这样使用时在子类中找不到父类的函数:$this->function_name()
问题描述
我正在查看一些 PHP 代码。有一个类 LQDM_Shortcodes_Run_Base 扩展了 WDS_Shortcodes。然后它尝试使用父类的公共函数att
。在 PhpStorm 中,它提醒我
att
找不到方法LQDM_Shortcodes_Run_Base
为什么找不到?子类确实在其自己的构造函数中调用父类的构造函数:
public function __construct( LQDM_Sermons $sermon ) {
$this->sermons = $sermons;
parent::__construct();
}
子类中的调用如下所示:
protected function get_sermon() {
$sermon_id = $this->att( 'sermon_id' );
...
}
父类的函数如下所示:
class WDS_Shortcodes {
...
public function att( $att, $default = null ) {
...
}
...
}
解决方案
推荐阅读
- c - 使用 fseek 在 C 中重写文件
- spring - 如何有选择地使一个类成为应该在 Spring (Spring Boot 2.x) 中运行的代码
- c++ - C ++将引用传递给同一类中的函数
- node.js - ExpressJS 中间件方法使变量在其他(模块)文件中可用
- c++ - C++如何创建一个不允许模板参数的类模板
- java - Random.nextInt() 返回相同的数字
- windows - 为什么顶级窗口的 GetParent(hwnd) 和 (HWND)::GetWindow(hwnd, GW_OWNER) 会给出不同的结果?
- python - 发现具有特定标准的排列三元组中的可能组合
- javascript - 带有自己的路由文件的 Vue.js + MPA
- java - 范围问题 - 额外添加意图并从 2 个不同的功能开始活动