Help with Net_DNS plz

Discussion in 'PHP' started by Katanius, Jun 7, 2007.

  1. #1
    Hi,
    I need to make an mx request to a host sto i installed the Net_DNS package. I copy pasted this code from the developers site:
    
    <?php
    
    // include class file
    include("Net/DNS.php");
    
    // create object
    $ndr = new Net_DNS_Resolver();
    
    // query for IP address
    $answer = $ndr->search("www.cnet.com", "MX");
    
    // print output
    $answer->answer[0]->display();
    echo "<br>";
    $answer->answer[1]->display();
    ?>
    
    Code (markup):
    I execute it and i get the following two errors:

    Notice: Trying to get property of non-object in C:\Program Files\Apache Group\Apache2\htdocs\dns\dnsspec.php on line 13

    Fatal error: Call to a member function display() on a non-object in C:\Program Files\Apache Group\Apache2\htdocs\dns\dnsspec.php on line 13

    What does this mean? How can i fix it and make it work?
     
    Katanius, Jun 7, 2007 IP
  2. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #2
    you need to initiate the object in order to use it. www.php.net/oop

    what is $ndr? it should be initiated. $ndr = new ClassName;
     
    ansi, Jun 7, 2007 IP
  3. HypertextFever

    HypertextFever Peon

    Messages:
    158
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perhaps the pathing is invalid in your include of the DNS.php script.

    From your .php file (the one with the code you've posted here) is the DNS.php file located in a subfolder named "Net" (case sensitive)?
     
    HypertextFever, Jun 7, 2007 IP
  4. Katanius

    Katanius Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    this is my include path: ;include_path = "C:\PHP5\PEAR"
    and this is my php instalation dir:
    C:\PHP5
    the package is installed in:
    C:\PHP5\PEAR\Net
    and i use php5

    The dns.php file is part of the pear package.

    The package documentation says that it cannot be called statically. I thought that $ndr = new Net_DNS_Resolver(); initiates the object. Net_DNS_Resolver is the name of the object. should it be something like:
    DNS::Net_DNS_Resolver($ndr); or DNS->Net_DNS_Resolver($ndr); Im kind of confused because php4 and 5 initiate objects difrently and im not very familiar with objects and classes.
     
    Katanius, Jun 8, 2007 IP
    HypertextFever likes this.
  5. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #5
    yeah you are initiating it, i must have overlooked that the first time. apologies.
     
    ansi, Jun 8, 2007 IP
  6. Katanius

    Katanius Peon

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    so any ideas why its not working? should it be initiated diferently?
     
    Katanius, Jun 9, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    not quite sure here. pear and i dont get along to well.
     
    ansi, Jun 9, 2007 IP