chaining methods and properties in php

In the previous lesson we learnt how to use $this keyword with the syntax and example.

In this chapter we will learn making chain to methods and properties. We use this chain word in daily life. It is same as cycle chain. One block is connected to another block.

Here method and properties chaining works same as it works in real life scenario. Let’s see this with an example.

 

In the above example we have one property name “firstName”, three methods i.e  hello(), registration(), and mail().

we created object using $user1 = new User();
Then we set value to property firstName.
and at last we chained methods to each other $user1-> hello()-> registration()-> mail();

Lets see example, what is going on.

Leave a Reply

Your email address will not be published. Required fields are marked *