Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Aug 2007
    Location
    tokyo
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Invoke function from initiated class within a class

    PHP Code:
    <?php
    //clsrecordset.php
    class Recordset extends Database{

        public function 
    Recordset( ) { }

        public function 
    query( ) { }

        public function 
    endOfFile ( ) { }

    }
    ?>
    PHP Code:
    <?php
    //clssearchindex.php
    require_once('clsrecordset.php');

    class 
    Searchindex {
        private 
    c_rs;

        public function 
    Searchindex ( ) {
            
    $this->c_rs = new Recordset( );
        }

        public function 
    getSQL ( ) { }

        public function 
    getData ( ) {
            
    $rs $this->c_rs->query($this->getSQL());    // error occurred this line
            
    $this->c_rs->query($this->getSQL());
            if ( 
    $this->c_rs->endOfFile() ) {
                
    $norecs true;
            }
        }
    }
    ?>
    Error message: Call to a member function query() on a non-object

    Additional, when I type the $this->c_rs-> , there is no intellisense on this case that's why I know there is something wrong and couldn't find the function.

    Help: How can I call the function from the initiated class in order to use in other class?

  • #2
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That error means that $c_rs has not been instantiated at the time you call Searchindex::getData(). I see that you're using a PHP4 style constructor, but your use of visibility keywords tells me that you're running PHP5. PHP5 should use the PHP4 style constructor if there's no __construct() function, but perhaps something strange has occurred? Maybe switching to __construct() will change something?

    It will be easier to debug if you post the rest of your code.

  • #3
    New Coder
    Join Date
    Aug 2007
    Location
    tokyo
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Invoke function from initiated class within a class [CLOSED]

    I am very sorry guys I just missed looked / overlooked the code.

    The code posted here was different in my source code.

    PHP Code:
    <?php
    class Searchindex ( ) {
        private 
    $c_rs;
        
        public function 
    Searchindex ( ) {
            
    /* this is the problem. 
             * It should be $this->c_rs = new Recordset ( );
            */
            
    $c_rs = new Recordset ( );    
        }
    }
    ?>
    I make my own headache .. Thanks guys.

    TOPIC CLOSED
    Last edited by erosszz; 08-24-2007 at 03:44 AM.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Additional, when I type the $this->c_rs-> , there is no intellisense on this case that's why I know there is something wrong and couldn't find the function.
    I don't think that's a trusty source of information. No client I know of has a dependable intellisense feature.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •