Thursday, December 19, 2013

what does return $this mean in php oops ?

This way of coding is called fluent interfacereturn $this returns the current object, so you can call multiple function as single object/line
code like this: do you know about method chaining if no ,then you can find here :)
instead of:
Here is you can find real example 

class a{
    public $name='';
    public function setName($name){
        return $this;
      public function getName(){
        return $this;

Create an object to call method-chaining
$obja=new a();
echo $name->name;
Hope this class may help you :)

No comments:

Post a Comment