从类中的已启动类调用函数 [英] Invoke function from initiated class within a class
问题描述
[PHP]
<?php
//clsrecordset.php
class Recordset扩展数据库{
公共函数Recordset(){}
public function query(){}
public function endOfFile(){ }
}
?> [/ PHP]
[PHP]<?php
//clssearchindex.php
require_once(''clsrecordset.php'');
class Searchindex {
private c_rs;
公共功能Searchindex(){
$ this-> c_rs = new Recordset();
}
公共函数getSQL(){}
公共函数getData(){
$ rs = $ this-> c_rs-> query($ this-> getSQL()); //此行发生错误
$ this-> c_rs-> query($ this-> getSQL());
if($ this-> c_rs-> endOfFile()){
$ norecs = true;
}
}
}
?> [/ PHP]
错误信息:在非对象上调用成员函数query()
另外,当我输入 $ this-> c_rs-> 时,在这种情况下没有智能感知这就是为什么我知道有有些不对劲,无法找到功能。
帮助:如何从启动的类中调用函数以便在其他类中使用?
this-> c_rs = new Recordset();
}
public function getSQL(){}
公共函数getData(){
rs =
this-> c_rs - >查询(
[PHP]
<?php
//clsrecordset.php
class Recordset extends Database{
public function Recordset( ) { }
public function query( ) { }
public function endOfFile ( ) { }
}
?>[/PHP]
[PHP]<?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;
}
}
}
?>[/PHP]
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?
this->c_rs = new Recordset( );
}
public function getSQL ( ) { }
public function getData ( ) {
rs =
this->c_rs->query(
这篇关于从类中的已启动类调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!