我有这个功能:
function getTitle(){
$crawler = new DOM_Crawler($this->url);
try{
if ( $title = $crawler->getPage()->getPageTitle()) {
$this->debug_element("title", $title);
unset($crawler);
return $title;
} else {
unset($crawler);
return self::TITLE_FETCH_WARN;
}
}
catch(Exception $e){
return self::TITLE_FETCH_WARN;
}
}
我正在尝试阻止crawler ...是一个非对象,并防止抛出该错误..尝试并捕获..所以我怎样才能捕获异常?
致命错误:在第163行的C:\ Program Files(x86)\ Zend \ Apache2 \ htdocs \ backlinks \ cron \ Backlinks.php中的非对象上调用成员函数getPageTitle()
答案 0 :(得分:2)
尝试
$page = $crawler->getPage();
if ($page && ($title = $page->getPageTitle())) {