trait MagicDataSet { public function getAttributeValue(string $attribute) { if (!$this->hasAttribute($attribute)) { throw new MissingAttributeException('$attribute is missing'); } return get_object_vars($this)[$attribute]; } public function hasAttribute(string $attribute): bool { return array_key_exists($attribute, get_object_vars($this)); } } class Post implements DataSetInterface { use MagicDataSet; public string $title; public string $description; }