PHP外文名:PHP: Hypertext Preprocessor,中文名:超文本预处理器是一种通用开源脚本语言。可以是未实例化的类名直接调用。下面由小编整理了几种php调用类中的方法,希望对大家有所帮助。
php调用类中的方法一
class foo{
function bar() {
return $this;
}
function hello() {
echo "Hello";
}
}
$foo = new foo();
$foo->bar()->bar()->bar()->bar()->hello();
?> php调用类中的方法二
class example {
var $name;
var $sex;
function name($name) {
$this->name = $name;
return $this;
}
function sex($sex) {
$this->sex = $sex;
return $this;
}
function trace() {
print("Name: {$this->name},Sex: {$this->sex}");
}
}
$person = new example;
$person->name("lisha")->sex(