0

When i use the some php frameworks or libraries i can write code like this:

$avariable = new aClass();
$avariable->someFunction()->somevalue

(I want to create structure like this.)

I try create a class name Customer

class Customer {
  public function getCustomer($name,$email,$age){
    ...
    $customer = new \stdClass();
    $customer->description = 'Description';

    return $customer;
  }
}

And then try $customer= new Customer(); $customer->getCustomer('name','email','age')->description ;

Why my code is not work

$customer->getCustomer('name','email','age')->description;

thanks

devugur
  • 1,339
  • 1
  • 19
  • 25

1 Answers1

0

Perhaps if 'description' is a method that returns a value within the Customer class It should work.

class Customer {
   public function getCustomer($name,$email,$age){
    ...
       $customer = new \stdClass();
       $customer->description = 'Description';

       return $customer;
   }
   function description()
   {
       return $something;
   }
}
$customer= new Customer();
$customer->getCustomer('name','email','age')->description() ;
Jayish
  • 76
  • 1
  • 4