Slide 29
Slide 29 text
© 2012-2024 BASE, Inc. 29
title = $title;
$this->content = $content;
$this->setStatus($status);
}
public function setStatus($status)
if (!in_array($status, ['draft', 'published',
'archived'])) {
throw new InvalidArgumentException('Invalid
status');
}
$this->status = $status;
}
public function getStatus(): string
{
return $this->status;
}
// 実行イメージ
$blog = new BlogPost(
title: 'New blog post',
content: 'This is the content of the blog post.',
status: PostStatus::Draft
);
var_dump($blog->getStatus()); // 'draft'
$blog->setStatus('published');
var_dump($blog->getStatus()); // 'published'
PHP8の機能を使わないパターン