use*_*061 7 php simple-html-dom
我在我的代码的第71行收到此错误,但是这行的功能正确执行,它完成了我期望它做的事情.
但是,我注意到我的错误日志中充满了这些行:
[2013年12月14日14:54:02 UTC] PHP致命错误:在第71行的/home/sportve/public_html/open_event_common.php中调用非对象的成员函数find()
我检查了什么:
simple_html_dom_parser 已包含,并且第71行打算执行的此功能正在运行.
这是我的代码的第71行:
$content->find('a.openevent', 0)->innertext = '';
Run Code Online (Sandbox Code Playgroud)
所以它的错误导致这个错误出现在我的错误日志文件中?
编辑:这是完整的代码:
<?php
$url = "static/" . $cat_map[$cat]['url'];
$html = file_get_html($url);
$content = $html->find('div#event-pane > div#e' . $event_id, 0);
$content->find('a.openevent', 0)->innertext = '';
$content->find('h3.lshtitle', 0)->onclick = '';
$content->find('h3.lshtitle', 0)->tag = 'div';
$content->find('div.lshtitle', 0)->class = 'ttl';
?>
Run Code Online (Sandbox Code Playgroud)
Jak*_*uld 16
根据您所提供的最好的,最实用的解决方案的信息是简单地做一个检查,看是否$html和$content为空.
当你得到一个"调用非对象的成员函数[无论函数是什么]"时,10次中有9次,这基本上意味着该对象不存在.意味着变量是空的.这是你的代码重做:
$url = "static/" . $cat_map[$cat]['url'];
if (!empty($url)) {
$html = file_get_html($url);
if (!empty($html)) {
$content = $html->find('div#event-pane > div#e' . $event_id, 0);
if (!empty($content)) {
$content->find('a.openevent', 0)->innertext = '';
$content->find('h3.lshtitle', 0)->onclick = '';
$content->find('h3.lshtitle', 0)->tag = 'div';
$content->find('div.lshtitle', 0)->class = 'ttl';
}
}
}
Run Code Online (Sandbox Code Playgroud)
另外,我添加了一个检查,看看它是否$url也是空的.
| 归档时间: |
|
| 查看次数: |
44435 次 |
| 最近记录: |