type = $type; $this->value = $value; $this->length = $length; } public function jsonSerialize() : array { $res = [$this->type => $this->value]; foreach (['length', 'editor', 'items', 'collapsed'] as $k) { if ($this->{$k} !== null) { $res[$k] = $this->{$k}; } } return $res; } }