1

I have got this function :

        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;
            }
}

I am trying to prevent crawler..be a non object and prevent that error from being thrown.. try and catch ..so how can I catch the exception ?

Fatal error: Call to a member function getPageTitle() on a non-object in C:\Program Files (x86)\Zend\Apache2\htdocs\backlinks\cron\Backlinks.php on line 163

Dmitry Makovetskiyd
  • 6,942
  • 32
  • 100
  • 160

1 Answers1

2

Try

$page = $crawler->getPage();
if ($page && ($title = $page->getPageTitle())) {
Sergey
  • 5,208
  • 25
  • 36
  • @DmitryMakovetskiyd, try catch do not catch `fatal error`, when you call variable = null you raise fatal error. For catch `fatal error` you need look for `error handling` on php.net – Sergey May 24 '12 at 08:02