Add properties to stdClass object from another object

前端 未结 4 1862
悲哀的现实
悲哀的现实 2021-02-07 04:26

I would like to be able to do the following:

$obj = new stdClass;
$obj->status = \"success\";

$obj2 = new stdClass;
$obj2->message = \"OK\";
4条回答
  •  耶瑟儿~
    2021-02-07 04:48

    if the object is the instance of stdClass (that's in your case) you can simply extend your object like...

    $obj = new stdClass;
    $obj->status = "success";
    
    $obj2 = new stdClass;
    $obj2->message = "OK";
    
    $obj->message = $message;
    $obj->subject = $subject;
    

    .... and as many as you wish.

提交回复
热议问题