{"id":11747,"date":"2022-03-03T10:00:00","date_gmt":"2022-03-03T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=11747"},"modified":"2022-03-03T10:13:24","modified_gmt":"2022-03-03T01:13:24","slug":"awesome-features-of-php-8","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/11747","title":{"rendered":"Awesome features of PHP 8"},"content":{"rendered":"\n<p>PHP 8 has been officially released for general users.  PHP 8 brings a host of new features improvements, functions, and deprecations to the language compared to PHP 7. Among all of these new features, the JIT compiler is the one sharing the limelight. However, other features like syntax changes are also to be taken into account as it is these features that will have a greater impact on the practitioners.<\/p>\n\n\n\n<p><strong>New features<\/strong> include:<\/p>\n\n\n\n<ul><li>Named arguments<\/li><li>Union types<\/li><li>Constructor property promotion<\/li><li>Custom object serialization<\/li><li>Match expression<\/li><li>Nullsafe operator<\/li><li>Improvements in the type system and error handling<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>New PHP Functions<\/strong><\/p>\n\n\n\n<ul><li>New str_contains() function<\/li><li>New str_starts_with() and str_ends_with() functions<\/li><li>New fdiv() function<\/li><li>get_debug_type() function<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>&#8212; <strong>str_contains()<\/strong><\/p>\n\n\n\n<p>Helps us in determining whether the given sub-string is present inside the string.<\/p>\n\n\n\n<p>Example<strong> :<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>str_contains ( string $austin , string $tin ) : bool<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Executes a case-sensitive operations and checks whether the string austin contains the substring tin.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>&nbsp;&#8212; string_starts_with and str_ends_with()<\/strong><\/p>\n\n\n\n<p>Using this function we can easily find whether the given sub-string is at the beginning or ending of the string.<\/p>\n\n\n\n<p>Example<strong>:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>str_starts_with(string $austin, string $au): bool;\n\nstr_ends_with(string $austin, string $tin): bool;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>These new functions can be impersonated with&nbsp;<code>strpos<\/code>,&nbsp;<code>substr<\/code>,&nbsp;<code>strncmp<\/code>, and&nbsp;<code>substr_compare<\/code>. However, the new functions were favourably received due to its engine-level optimizations and their regular use cases.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>&#8212; <strong>fdiv() <\/strong><\/p>\n\n\n\n<p>The new fdiv() function has similar ability as the fmod() and intdiv() functions, that allows for division by 0. Instead of getting errors, you\u2019ll get INF, -INF, or NAN, depending on the scenario.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>&#8212; <strong>get_debug_type()<\/strong><\/p>\n\n\n\n<p>The new get_debug_type function always returns the true native type of variables. It returns a return native type names, e.g., int rather than integer, double instead of float.<\/p>\n\n\n\n<p>get_debug_type() function helps in<\/p>\n\n\n\n<p> <li>Error reporting<\/li><\/p>\n\n\n\n<p><li>Debugging<\/li><\/p>\n\n\n\n<p><li>Business logic<\/li> <\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>By Tsuki<\/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\/11747\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/11747\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Awesome features of PHP 8\" 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\/11747\" data-text=\"Awesome features of PHP 8\" 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\/11747\" 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\/11747\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>PHP 8 has been officially released for general users. PHP 8 brings a host of new features improvements, functi [&hellip;]<\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[35],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11747"}],"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\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=11747"}],"version-history":[{"count":2,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11747\/revisions"}],"predecessor-version":[{"id":11750,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/11747\/revisions\/11750"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=11747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=11747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=11747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}