Call to a non object fatal error

This is a discussion on "Call to a non object fatal error" within the PHP Forum section. This forum, and the thread "Call to a non object fatal error are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Feb 11th, 2008, 17:52
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Call to a non object fatal error

Hey guys, I rarely have problems with PHP but I've been using .NET for a few weeks now I've probably become a little rusty.

This is my code:
PHP: Select all

<?php
$dom 
= new DOMDocument();
$dom->loadHTMLFile('http://www.alexgeek.co.uk');
$slctr = new DOMTagSelector($dom);
echo 
$slctr->selectSingleText("//title");
class 
DOMTagSelector {
    private 
$dom;
    private 
$xpath;
    function 
__contruct($d)
    {
        
$this->dom $d;
        
$this->xpath = new DOMXPath($d);
    }
    function 
selectSingleNode($query)
    {
        
$node $this->xpath->query($query); // line 19
        
return $node;
    }
    function 
selectSingleText($query)
    {
        
$node $this->selectSingleNode($query);
        return 
$node->item(0)->nodeValue;
    }
}
?>
And the error:
Code: Select all
Fatal error:  Call to a member function query() on a non-object in C:\web\aspNETtesting\test.php on line 19
It seems the DOM object isn't passed correctly and the private properties are set to null.

A little help?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Feb 20th, 2008, 16:42
Junior Member
Join Date: Feb 2008
Location: Poreč
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Call to a non object fatal error

__contruct -> __construct !

(the xpath was never initialized!)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Feb 21st, 2008, 15:34
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Call to a non object fatal error

Damn my bad eyes! Good catch, thanks.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Copy to clipboard Object Error andrewlondon JavaScript Forum 1 Sep 24th, 2007 13:15
fatal error alexgeek Webforumz Cafe 3 Aug 27th, 2007 22:16
Fatal error: call to a member function funtion() on a non-object timcallagy Databases 2 Mar 4th, 2007 21:55
Fatal error: Call to a member function getName() on a non-object jono PHP Forum 1 Apr 13th, 2006 18:53
Having trouble with scripts. Fatal error: Call to undefined function: imagegif() cargi PHP Forum 5 Jan 6th, 2006 18:59


All times are GMT. The time now is 02:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42