PHP 7.2 real app usage:
public function jsonSerialize()
{
$m1 = memory_get_usage();
$json_class = new class implements SpecExportInterface {
public $id;
public $status;
public $code;
public $title;
public $source;
public $links;
};
$m2 = memory_get_usage();
$json_class->id = $this->id;
$json_class->status = $this->status;
$json_class->code = $this->code;
$json_class->title = $this->title;
$json_class->source = $this->source;
$json_class->links = $this->links;
$m3 = memory_get_usage();
$a1 = [];
$m4 = memory_get_usage();
$a1['id'] = $this->id;
$a1['status'] = $this->id;
$a1['code'] = $this->id;
$a1['title'] = $this->id;
$a1['source'] = $this->id;
$a1['links'] = $this->id;
$a1['id'] = $this->id;
$m5 = memory_get_usage();
echo 'class create:' . ($m2-$m1) . '</br>'
.'class assign:' . ($m3-$m2) . '</br>'
.'array create:' . ($m4-$m3) . '</br>'
.'array assign:' . ($m5-$m4) . '</br>'
;die;
return $json_class;
}
Results:
class create: 168 bytes
class assign: 0 bytes
array create: 0 bytes
array assign: 376 bytes