wordpress - 调用未定义函数 request_currencies()
问题描述
WordPress 5.2.4
class ved_currencies extends WP_Widget {
function __construct() {
parent::__construct(
‘ved_currencies’,
"Ved currencies",
array( 'description' =>'Show currencies'));
}
private function request_currencies(){
$date_req= time();
$currencies = ["USD", "CNY", "EUR", "JPY", "BYN", "KZT", "UAH"];
}
public function widget( $args, $instance ){
request_currencies(); // Line 30.
echo "test";
}
}
结果:
Uncaught Error
: Call to undefined function request_currencies() in
C:\OSPanel\domains\ved\wp-content\plugins\ved-currencies\ved-currencies.php
on line
30
代码示例中标记了第 30 行。
你能帮我理解为什么会出现这个错误吗?
解决方案
this关键字在类内部使用,通常与成员函数一起访问当前对象的类(变量或函数)的非静态成员。
class ved_currencies extends WP_Widget {
function __construct() {
parent::__construct(
‘ved_currencies’,
"Ved currencies",
array( 'description' =>'Show currencies'));
}
private function request_currencies(){
$date_req= time();
$currencies = ["USD", "CNY", "EUR", "JPY", "BYN", "KZT", "UAH"];
}
public function widget( $args, $instance ){
$this->request_currencies(); // Line 30.
echo "test";
}
}
我已经使用 $this->request_currencies(); 调用了该函数。
为了您更好地理解,请访问此链接
推荐阅读
- android - Notificationmanager.notify 不显示通知
- sql-server - SQL Server:在上次备份和日志备份运行超过一天时配置电子邮件通知
- javascript - 如何强制向上滚动 2 合一页 HTML 文档?
- visual-studio-code - 如何创建等效于 cuda makefile 的 ms vs code
- javascript - 为什么我的客户端在 jquery 更新(从 1.11.2 到 3.5.1)后没有收到带有 SignalR 的广播消息?
- asp.net - 识别混淆/加密方法
- angular - 嵌套 ControlValueAccessor 的角度验证状态未在父级中正确传播,如何实现此验证?
- javascript - 在地图中取属性的值,但在javascript中使用不同属性的名称
- javascript - VSCode CompletionItems 显示在列表底部
- android - Android Studio 下载音乐 youtube 视频