PHP benefits for chaining?

Still on the PHP-OOP tutorial wheels, this question may belong to failblog.org . =)

What are the advantages of the method chain in PHP?

I'm not sure if this is important, but I will call my method statically. eg.

$foo = Bar::get('sysop')->set('admin')->render();

From what I read, any method that returns $thiscan be bound. I just found out that this is new in PHP5. It seems to me that there may be speed benefits if I do not need to instantiate a new object (set it statically) and just select several methods that I need from the class?

Do I have this right?

+3
source share
3 answers

, .

- . :

$foo = Bar::get('sysop');
$foo -> set('admin');
$foo -> render();

: IDE (, Eclipse) ( $foo), .

+6

; . , .

, , , , ( , null ). ​​

, ; . , .

0

if I don’t need to instantiate the whole new object (its static call) and just select some methods that I need from the class?

Wrong! To return $this, a class must be created.

0
source

Source: https://habr.com/ru/post/1726827/


All Articles