{"id":308269,"date":"2020-08-10T15:01:09","date_gmt":"2020-08-10T15:01:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308269"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-08-10T15:01:09","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308269","title":{"rendered":"PHP 8: \u043a\u043e\u0434 \u00ab\u0414\u043e\u00bb \u0438 \u00ab\u041f\u043e\u0441\u043b\u0435\u00bb (\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0441 PHP 7.4)"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/vdsina\/blog\/514512\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/73\/dk\/a3\/73dka35dcy3bu2mlhurd-f1vixk.jpeg\"><\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 PHP 8, \u0438 \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u0438 \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0443\u0436\u0435 \u043d\u0430\u0447\u0430\u043b\u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0430 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u041f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438<\/h2>\n<p>  \u042f \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043d\u0435 \u0437\u043b\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043d\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043d\u0438 \u043e\u0447\u0435\u043d\u044c \u0434\u0430\u0436\u0435 \u043a\u0441\u0442\u0430\u0442\u0438.<\/p>\n<p>  \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043d\u0430\u0434 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438, \u0433\u0434\u0435 \u0442\u0430\u043a\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0431\u044b\u043b\u043e \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e. \u0412\u043e\u0437\u044c\u043c\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"php\">class CartsProjector implements Projector {     use ProjectsEvents;      protected array $handlesEvents = [         CartStartedEvent::class =&gt; 'onCartStarted',         CartItemAddedEvent::class =&gt; 'onCartItemAdded',         CartItemRemovedEvent::class =&gt; 'onCartItemRemoved',         CartExpiredEvent::class =&gt; 'onCartExpired',         CartCheckedOutEvent::class =&gt; 'onCartCheckedOut',         CouponAddedToCartItemEvent::class =&gt; 'onCouponAddedToCartItem',     ];      public function onCartStarted(CartStartedEvent $event): void     { \/* \u2026 *\/ }      public function onCartItemAdded(CartItemAddedEvent $event): void     { \/* \u2026 *\/ }      public function onCartItemRemoved(CartItemRemovedEvent $event): void     { \/* \u2026 *\/ }      public function onCartCheckedOut(CartCheckedOutEvent $event): void     { \/* \u2026 *\/ }      public function onCartExpired(CartExpiredEvent $event): void     { \/* \u2026 *\/ }      public function onCouponAddedToCartItem(CouponAddedToCartItemEvent $event): void     { \/* \u2026 *\/ } }<\/code><\/pre>\n<p>  <i>PHP 7<\/i><\/p>\n<p>  \u0423 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0432 PHP 8 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430:<\/p>\n<ul>\n<li>\u041a\u043e\u0434 \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0441\u043e\u0431\u0440\u0430\u043d \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0438 \u043c\u043d\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0434\u043e \u043d\u0430\u0447\u0430\u043b\u0430, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044c.<\/li>\n<li>\u041c\u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0438\u0442\u044c\u0441\u044f \u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a (\u043a\u043e\u0433\u0434\u0430 IDE \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0445 \u0430\u0432\u0442\u043e\u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c, \u043d\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u043f\u0435\u0447\u0430\u0442\u043e\u043a \u0438 \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432).<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"php\">class CartsProjector implements Projector {     use ProjectsEvents;      @@SubscribesTo(CartStartedEvent::class)     public function onCartStarted(CartStartedEvent $event): void     { \/* \u2026 *\/ }      @@SubscribesTo(CartItemAddedEvent::class)     public function onCartItemAdded(CartItemAddedEvent $event): void     { \/* \u2026 *\/ }      @@SubscribesTo(CartItemRemovedEvent::class)     public function onCartItemRemoved(CartItemRemovedEvent $event): void     { \/* \u2026 *\/ }      @@SubscribesTo(CartCheckedOutEvent::class)     public function onCartCheckedOut(CartCheckedOutEvent $event): void     { \/* \u2026 *\/ }      @@SubscribesTo(CartExpiredEvent::class)     public function onCartExpired(CartExpiredEvent $event): void     { \/* \u2026 *\/ }      @@SubscribesTo(CouponAddedToCartItemEvent::class)     public function onCouponAddedToCartItem(CouponAddedToCartItemEvent $event): void     { \/* \u2026 *\/ } }<\/code><\/pre>\n<p>  <i>PHP 8<\/i><\/p>\n<h2>Static \u0432\u043c\u0435\u0441\u0442\u043e doc-\u0431\u043b\u043e\u043a\u043e\u0432<\/h2>\n<p>  \u042d\u0442\u043e \u043d\u0435 \u0442\u0430\u043a\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u043d\u043e \u044f \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0441\u044c \u0441 \u044d\u0442\u0438\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c. \u042f \u0447\u0430\u0441\u0442\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u044e, \u0447\u0442\u043e \u043c\u043d\u0435 \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0443\u0436\u043d\u044b doc-\u0431\u043b\u043e\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u043c\u0435\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f static.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0432 PHP 7.4 \u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"php\">\/**  * @return static  *\/ public static function new() {     return new static(); }<\/code><\/pre>\n<p>  <i>PHP 7.4<\/i><\/p>\n<p>  \u0422\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e:<\/p>\n<pre><code class=\"php\">public static function new(): static {     return new static(); } <\/code><\/pre>\n<p>  <i>PHP 8<\/i><\/p>\n<h2>DTO, \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0438 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/h2>\n<p>  \u042f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u0430\u043b \u043e\u0431 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0442\u0438\u043f\u043e\u0432 PHP \u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 DTO (<a href=\"https:\/\/stitcher.io\/blog\/laravel-beyond-crud-02-working-with-data\">data transfer objects<\/a>). \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u044f \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e DTO \u0432 \u0441\u0432\u043e\u0451\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044f \u0441\u0447\u0430\u0441\u0442\u043b\u0438\u0432, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u043c\u0435\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e:<\/p>\n<pre><code class=\"php\">class CustomerData extends DataTransferObject {     public string $name;      public string $email;      public int $age;          public static function fromRequest(         CustomerRequest $request     ): self {         return new self([             'name' =&gt; $request-&gt;get('name'),             'email' =&gt; $request-&gt;get('email'),             'age' =&gt; $request-&gt;get('age'),         ]);     } }  $data = CustomerData::fromRequest($customerRequest);<\/code><\/pre>\n<p>  <i>PHP 7.4<\/i><\/p>\n<p>  \u0412\u043e\u0442, \u0442\u0430\u043a-\u0442\u043e \u043b\u0443\u0447\u0448\u0435:<\/p>\n<pre><code class=\"php\">class CustomerData {     public function __construct(         public string $name,         public string $email,         public int $age,     ) {} }  $data = new CustomerData(...$customerRequest-&gt;validated());<\/code><\/pre>\n<p>  <i>PHP 8<\/i><\/p>\n<p>  \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0414\u0430, \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432 \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 Spread.<\/p>\n<h2>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 match <\/h2>\n<p>  \u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f?<\/p>\n<pre><code class=\"php\">\/**  * @method static self PENDING()  * @method static self PAID()  *\/ class InvoiceState extends Enum {     private const PENDING = 'pending';     private const PAID = 'paid';      public function getColour(): string     {         return [             self::PENDING =&gt; 'orange',             self::PAID =&gt; 'green',         ][$this-&gt;value] ?? 'gray';        } }<\/code><\/pre>\n<p>  <i>PHP 7.4<\/i><\/p>\n<p>  \u042f \u0431\u044b \u0441\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439 \u0432\u0430\u043c \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043d\u043e \u0435\u0441\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u042d\u0442\u043e\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0443\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u043e\u0433\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"php\">\/**  * @method static self PENDING()  * @method static self PAID()  *\/ class InvoiceState extends Enum {     private const PENDING = 'pending';     private const PAID = 'paid';      public function getColour(): string     {         if ($this-&gt;value === self::PENDING) {             return 'orange';         }              if ($this-&gt;value === self::PAID) {             return 'green'         }          return 'gray';     } }<\/code><\/pre>\n<p>  <i>PHP 7.4 \u2014 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/i><\/p>\n<p>  \u041d\u043e \u0432 PHP 8 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c match.<\/p>\n<pre><code class=\"php\">\/**  * @method static self PENDING()  * @method static self PAID()  *\/ class InvoiceState extends Enum {     private const PENDING = 'pending';     private const PAID = 'paid';      public function getColour(): string     {         return match ($this-&gt;value) {             self::PENDING =&gt; 'orange',             self::PAID =&gt; 'green',             default =&gt; 'gray',         }; }<\/code><\/pre>\n<p>  <i>PHP 8<\/i><\/p>\n<h2>\u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0432\u043c\u0435\u0441\u0442\u043e doc-\u0431\u043b\u043e\u043a\u043e\u0432<\/h2>\n<p>  \u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435 \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 static.<\/p>\n<pre><code class=\"php\">\/**  * @param string|int $input  *  * @return string   *\/ public function sanitize($input): string;<\/code><\/pre>\n<p>  <i>PHP 7.4<\/i><\/p>\n<pre><code class=\"php\">public function sanitize(string|int $input): string;<\/code><\/pre>\n<p>  <i>PHP 8<\/i><\/p>\n<h2>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/h2>\n<p>  \u0420\u0430\u043d\u044c\u0448\u0435 \u0432\u044b \u043d\u0435 \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c throw \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438, \u0430 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u043b\u043e, \u0447\u0442\u043e \u0432\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u043f\u0438\u0441\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438:<\/p>\n<pre><code class=\"php\">public function (array $input): void {     if (! isset($input['bar'])) {         throw BarIsMissing::new();     }          $bar = $input['bar'];      \/\/ \u2026 }<\/code><\/pre>\n<p>  <i>PHP 7.4<\/i><\/p>\n<p>  \u0412 PHP 8 throw \u0441\u0442\u0430\u043b\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"php\">public function (array $input): void {     $bar = $input['bar'] ?? throw BarIsMissing::new();      \/\/ \u2026 }<\/code><\/pre>\n<p>  <i>PHP 8<\/i><\/p>\n<h2>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 nullsafe<\/h2>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c null coalescing (\u043a\u043e\u0430\u043b\u0435\u0441\u0446\u0438\u0440\u0443\u044e\u0449\u0438\u0439), \u0432\u0430\u043c \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0435\u0433\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438: \u043e\u043d \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435 \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u043b\u0438 \u043d\u0443\u0436\u043d\u044b \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0438\u043b\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0446\u0435\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432:<\/p>\n<pre><code class=\"php\">$startDate = $booking-&gt;getStartDate(); $dateAsString = $startDate ? $startDate-&gt;asDateTimeString() : null;<\/code><\/pre>\n<p>  <i>PHP 7.4<\/i><\/p>\n<p>  \u0421 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 nullsafe \u044f \u043c\u043e\u0433\u0443 \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435.<\/p>\n<pre><code class=\"php\">$dateAsString = $booking-&gt;getStartDate()?-&gt;asDateTimeString();<\/code><\/pre>\n<p>  <i>PHP 8<\/i><\/p>\n<p>  \u0410 \u043a\u0430\u043a\u0438\u0435 \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 PHP 8 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0435 \u0432\u0430\u0436\u043d\u044b\u043c\u0438 \u0432\u044b?<\/p>\n<hr>\n<p>  <\/p>\n<h4>\u041d\u0430 \u043f\u0440\u0430\u0432\u0430\u0445 \u0440\u0435\u043a\u043b\u0430\u043c\u044b<\/h4>\n<p>  <a href=\"https:\/\/vdsina.ru\/cloud-servers?partner=habr59\">\u0421\u0435\u0440\u0432\u0435\u0440\u044b \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a> \u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432. \u041a\u0430\u0436\u0434\u044b\u0439 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d \u043a \u0437\u0430\u0449\u0438\u0449\u0451\u043d\u043d\u043e\u043c\u0443 \u043e\u0442 DDoS-\u0430\u0442\u0430\u043a \u043a\u0430\u043d\u0430\u043b\u0443 \u0432 500 \u041c\u0435\u0433\u0430\u0431\u0438\u0442, \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0441\u043e\u043a\u043e\u0441\u043a\u043e\u0440\u043e\u0441\u0442\u043d\u0443\u044e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0441\u0435\u0442\u044c. \u041c\u044b \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u0442\u0430\u0440\u0438\u0444\u043d\u044b\u0445 \u043f\u043b\u0430\u043d\u043e\u0432, \u0441\u043c\u0435\u043d\u0430 \u0442\u0430\u0440\u0438\u0444\u0430 \u0432 \u043e\u0434\u0438\u043d \u043a\u043b\u0438\u043a. \u041e\u0447\u0435\u043d\u044c <a href=\"https:\/\/habr.com\/ru\/company\/vdsina\/blog\/460107\/\">\u0443\u0434\u043e\u0431\u043d\u0430\u044f \u043f\u0430\u043d\u0435\u043b\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f<\/a> \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u043c\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c API. \u041f\u043e\u0441\u043f\u0435\u0448\u0438\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c!<\/p>\n<p>  <a href=\"https:\/\/vdsina.ru\/cloud-servers?partner=habr59\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/8p\/3v\/z4\/8p3vz47nluspfyc0axlkx88gdua.png\"><\/a><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/vdsina\/blog\/514512\/\"> https:\/\/habr.com\/ru\/company\/vdsina\/blog\/514512\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/vdsina\/blog\/514512\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/73\/dk\/a3\/73dka35dcy3bu2mlhurd-f1vixk.jpeg\"><\/p>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u0434\u043e \u0432\u044b\u0445\u043e\u0434\u0430 PHP 8, \u0438 \u0432 \u044d\u0442\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c, \u043a\u0430\u043a \u044d\u0442\u0438 \u043d\u043e\u0432\u043e\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0443\u0436\u0435 \u043d\u0430\u0447\u0430\u043b\u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434 \u0430\u0432\u0442\u043e\u0440\u0430 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308269","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308269"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308269\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}