我试图制作基于天气的PHP脚本来显示天气相关的数据.但是,我正面临这个错误消息
致命错误:调用未定义的方法weather :: get()
你能告诉我如何解决这个问题或者我的问题是什么?你可以在这里查看我的代码:
<?php
include 'weather.php';
$t_weather = new weather();
$info = $t_weather->get('New York');
echo "Current temperature in {$info[0]['location']} is: {$info[0]['current_condition']['temperature']['f']} °F";
?>
Run Code Online (Sandbox Code Playgroud)
这是weather.php:
<?php
class weather {
// API data
private $API_NAME = 'weather';
private $API_KEY = '***********';
}
?>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
那么你的weather类没有名为get的方法.你是否正在使用其他人的班级来做这件事?你应该有类似的东西:
class weather {
// API data
private $API_NAME = 'weather';
private $API_KEY = '***********';
public function get($location) {
// code that gets the weather for $location
}
}
Run Code Online (Sandbox Code Playgroud)