如何在任何Php类中创建可选对象?

如何在任何Php类中创建可选对象?,php,class,oop,Php,Class,Oop,当我使用一些php框架或库时,我可以编写如下代码: $avariable = new aClass(); $avariable->someFunction()->somevalue (我想创建这样的结构。) 我尝试创建一个类名Customer class Customer { public function getCustomer($name,$email,$age){ ... $customer = new \stdClass(); $customer

当我使用一些php框架或库时,我可以编写如下代码:

$avariable = new aClass();
$avariable->someFunction()->somevalue
(我想创建这样的结构。)

我尝试创建一个类名Customer

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

    return $customer;
  }
}
然后试试看

$customer=新客户();
$customer->getCustomer('name'、'email'、'age')->说明;

为什么我的代码不起作用

$customer->getCustomer('name'、'email'、'age')->说明


谢谢

如果“description”是一个在Customer类中返回值的方法,那么它应该可以工作

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() ;

看起来你想做你不工作是什么意思?它应该做什么?。。。我的代码不工作,不能很好地描述您的问题。请解释一下预期输出与当前输出的对比。只需测试一下你的输出就可以了。我得到了输出
说明
。。。