[英]PHP Class Function Calling
I'm writing my own php class and I have several functions within that class. 我正在编写自己的php类,并且该类中有多个函数。 But am I not allowed to call a function from another function within the same class?
但是,我不允许从同一类中的另一个函数调用一个函数吗? Something like this:
像这样:
class my_Class {
function one($arg) {
//does something
}
function two($var) {
$receive = one($var);
}
}
I tried something like this and it spat out an error saying: 我尝试了这样的事情,它吐出一个错误说:
Fatal error: Call to undefined function one()
What am I doing wrong? 我究竟做错了什么?
Change it to this: 更改为此:
function two($var) {
$receive = $this->one($var);
}
Review the PHP OOP reference: http://www.php.net/manual/en/language.oop5.php 查看PHP OOP参考: http : //www.php.net/manual/zh/language.oop5.php
The $this
keyword is always required. 始终需要
$this
关键字。
It should be 它应该是
class my_Class {
function one($arg) {
// does something
}
function two($var) {
$receive = $this->one($var);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.