Php 子方法是否没有访问父方法的权限';s变量?
它不是一个子方法,但它是在我的类中的另一个方法中调用的方法Php 子方法是否没有访问父方法的权限';s变量?,php,oop,syntax,scope,Php,Oop,Syntax,Scope,它不是一个子方法,但它是在我的类中的另一个方法中调用的方法Paginate 当我尝试运行此命令时: public function paginate() { // Other stuff here for ($i = $pageMin; (($i <= $pageMax) && ($i <= $this->arrayLength)); $i++) { $this->build(); // The important bit!
Paginate
当我尝试运行此命令时:
public function paginate() {
// Other stuff here
for ($i = $pageMin; (($i <= $pageMax) && ($i <= $this->arrayLength)); $i++) {
$this->build(); // The important bit!
}
// Other stuff here
}
public function build() {
echo $array[$i]['name'];
}
公共函数分页(){
//这里还有其他东西
对于($i=$pageMin;($i build();//重要的一点!
}
//这里还有其他东西
}
公共功能构建(){
echo$array[$i]['name'];
}
我被告知,$I在为我的build()
方法调用echo的行中是未定义的。$I
从build()
的角度来看是否相对全局
如何解决这个问题?当我在paginate()
中调用$I
时,是否必须将它作为参数传递给build()
?这看起来并不完全干净。替代方法?它们在不同的范围内
您必须使用参数传递它
$this->build($i);
--
@用户814064为什么?这是PHP,不是Javascript?
public function build($i) {
echo $array[$i]['name'];
}