从类中的已启动类调用函数 [英] Invoke function from initiated class within a class

查看:68
本文介绍了从类中的已启动类调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆