O
O
Overfinch2016-05-07 22:27:17
PHP
Overfinch, 2016-05-07 22:27:17

Multiple methods on same PHP object?

How to describe a class so that it would be possible to apply several methods to one object in PHP?
Like this:
$obj->foo()->bar();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2016-05-07
@Overfinch

the method must return a pointer to the instance: at the end of the method must be return $this;
https://en.wikipedia.org/wiki/Method_chaining#PHP

O
Overfinch, 2016-05-07
@Overfinch

Thanks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question