...

View Full Version : Invoke function from initiated class within a class



erosszz
08-24-2007, 03:06 AM
<?php
//clsrecordset.php
class Recordset extends Database{

public function Recordset( ) { }

public function query( ) { }

public function endOfFile ( ) { }

}
?>


<?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?

SteveBach
08-24-2007, 04:12 AM
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.

erosszz
08-24-2007, 04:42 AM
I am very sorry guys I just missed looked / overlooked the code.

The code posted here was different in my source 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

aedrin
08-24-2007, 05:01 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum