Open
Description
Hi, PHP 8.2 is the current version, and PHP 8.3 will come faster than we all think, therefore I want to start a new discussion, whether we should rewrite code samples to PHP 8.2 and start using "constructor property promotion" or not. What do you think about it?
Example Adapter code with constructor property promotion:
/**
* EN: The Adapter is a class that links the Target interface and the Adaptee
* class. In this case, it allows the application to send notifications using
* Slack API.
*
* RU: Адаптер – класс, который связывает Целевой интерфейс и Адаптируемый
* класс. Это позволяет приложению использовать Slack API для отправки
* уведомлений.
*/
class SlackNotification implements Notification
{
public function __construct(private readonly SlackApi $slack, private readonly string $chatId)
{
}
/**
* EN: An Adapter is not only capable of adapting interfaces, but it can
* also convert incoming data to the format required by the Adaptee.
*
* RU: Адаптер способен адаптировать интерфейсы и преобразовывать входные
* данные в формат, необходимый Адаптируемому классу.
*/
public function send(string $title, string $message): void
{
$slackMessage = "#" . $title . "# " . strip_tags($message);
$this->slack->logIn();
$this->slack->sendMessage($this->chatId, $slackMessage);
}
}
Metadata
Metadata
Assignees
Labels
No labels