{"id":11108,"date":"2021-12-06T10:00:00","date_gmt":"2021-12-06T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=11108"},"modified":"2021-12-03T20:28:46","modified_gmt":"2021-12-03T11:28:46","slug":"php-8-1-is-here","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/11108","title":{"rendered":"PHP 8.1 is here"},"content":{"rendered":"\n<p>The PHP team has released PHP 8.1. Let&#8217;s see a bit of some main features they have added.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/twitter.com\/official_php\/status\/1463943033234276360\n<\/div><\/figure>\n\n\n\n<h3>Improvements<\/h3>\n\n\n\n<p>There are many improvements as follow.<\/p>\n\n\n\n<ul><li>Enumerations<\/li><li>Readonly properties<\/li><li>Pure Intersection Types<\/li><li>never&nbsp;return type<\/li><li>First-class Callable Syntax<\/li><li>New&nbsp;array_is_list&nbsp;function<\/li><li>and many more<\/li><\/ul>\n\n\n\n<p>We will walk through some feature more details.<\/p>\n\n\n\n<h3>Enumerations<\/h3>\n\n\n\n<p>PHP 8.1 supports Enumerations (Enums) natively, providing an API&nbsp;for defining and working with Enums:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>enum Data\n{\n    case Draft;\n    case Published;\n    case Archived;\n}\nfunction acceptStatus(Data $data) {...}<\/code><\/pre>\n\n\n\n<h3>Read-only Properties<\/h3>\n\n\n\n<p>Read-only properties cannot be changed after they are initialized. You can be confident that your data classes are consistent. PHP 8.1 can reduce boilerplate by defining public properties the author does not intend to change.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Sample\n{\n    public readonly Data $data;\n \n    public function __construct(Data $data)\n    {\n        $this-&gt;data = $data;\n    }\n}<\/code><\/pre>\n\n\n\n<h3>First-class Callable Syntax<\/h3>\n\n\n\n<p>You can make make a closure from a callable by calling it and passing&nbsp;<code><strong>\"...<\/strong><\/code>&#8220;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function sum(int $a, int $b) {\n    \/\/ ...\n}\n \n$sum = sum(...);\n$sum(1, 5);\n$sum(5, 3);<\/code><\/pre>\n\n\n\n<p>and there are still more interesting features to look more detail. Please check the <a href=\"https:\/\/www.php.net\/releases\/8.1\/en.php\">official documentation<\/a> for more detail.<\/p>\n\n\n\n<p>Yuuma<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11108\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/11108\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"PHP 8.1 is here\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11108\" data-text=\"PHP 8.1 is here\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11108\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/11108\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>The PHP team has released PHP 8.1. Let&#8217;s see a bit of some main features they have added. Improvements T [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11108"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=11108"}],"version-history":[{"count":2,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11108\/revisions"}],"predecessor-version":[{"id":11111,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11108\/revisions\/11111"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=11108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=11108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=11108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}