I
I
ilya2002020-10-08 10:27:17
PHP
ilya200, 2020-10-08 10:27:17

How to describe the structure of a PHP object?

Good time,
php code: What will the classes that can describe such code look like?
$base->test('string1') ->chek('string')->hello;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton R., 2020-10-08
@ilya200

To make a "cascade" of successive methods, you need to return the same object in each method.

class Base {
  
  public function test($string){
    // Что то делаем.
    return $this;
  }
  
  public function chek($string){
    // Что то делаем.
    return $this;
  }
  
  public function hello(){
    // Что то делаем.
    return $this;
  }
}

And it is more convenient to write in code like this:
$base
->test('string1')
->chek('string')
->hello();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question