Home > Backend Development > PHP Tutorial > 在一行语句里调用一个类的多个方法,该如何写

在一行语句里调用一个类的多个方法,该如何写

WBOY
Release: 2016-06-13 12:05:37
Original
944 people have browsed it

在一行语句里调用一个类的多个方法,该怎么写?
比如这句:

$this->m_button6PaneInfo->Movable( false )->Dock()->Fixed()->BottomDockable( false )->TopDockable( false )->Layer( 10 )->ToolbarPane();
Copy after login

$this->m_button6PaneInfo 是一个类实例。后面的全是该类的方法。
这条语句是无法通过的,至少我的php版本无法通过。

除了拆成多行外,这条该怎么改?才能正确执行?
或者升级到哪个版本?才可以这样写
------解决方案--------------------
这样写
class testcls{<br />    function fun1(){<br />        echo 'fun1';<br />        return $this;<br />    }<br />    function fun2(){<br />        echo 'fun1';<br />        return $this;<br />    }<br />    function fun3(){<br />        echo 'fun3';<br />        return $this;<br />    }<br />}<br />$test = new testcls();<br />$test->fun1()->fun2()->fun3();
Copy after login

------解决方案--------------------
链式操作的前提,每次操作都返回对象本身。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template