{"id":3556,"date":"2020-11-27T04:24:58","date_gmt":"2020-11-27T04:24:58","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=3556"},"modified":"2020-11-27T06:33:13","modified_gmt":"2020-11-27T06:33:13","slug":"what-is-new-in-php8","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/","title":{"rendered":"What is new in PHP8?"},"content":{"rendered":"<p>PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved performance. Due to breaking changes users need to make some changes in their code to execute it on PHP8.<br \/>\nAs well some new features introduced in PHP8 are: JIT compiler, Match expression, Union type, Named argument, Constructor property promotion, Null safe operator, and more.<\/p>\n<h2>JIT compiler<\/h2>\n<p>It is Just in Time Compiler which translates the intermediate code into X86 machine code. Even though opcode is in low-level presentation still it needs to compile in X86 machine code. JIT uses the dynamic assembler for code generation engines rather than any additional intermediate representation to generate directly native code from PHP code.<br \/>\n<strong>Part of opcache:<\/strong> <\/p>\n<ol>\n<li>opcache.jit=on<\/li>\n<li>opcache.jit_buffer_size=128M<\/li>\n<\/ol>\n<p>Benefit: It provides better performance for math-heavy code, &#8220;typical&#8221; PHP web applications and it also provides fast speed as compared to c.<\/p>\n<h3>Match expression <\/h3>\n<p>It works as a switch function but with different features.<br \/>\nStrictly data type is checked in the match function.<br \/>\nIn switch after matching the case, multiple line code can be written but in the match() only one line code can be written.<br \/>\nIf the switch function does not give default, then it will execute net but in match, it will generate an error.<br \/>\nLength of the match() is less as compared to switch().<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p><code>&lt;?php<br \/>\nclass newphp8<br \/>\n{<br \/>\n    public function mathexp()<br \/>\n        {<br \/>\n            $expcode= 100;<br \/>\n            \tswitch($expcode)<br \/>\n              \t{<br \/>\n\t\t\t\t\tcase 100:<br \/>\n                    return \"successful\";<br \/>\n                    break;<br \/>\n                    case 200:<br \/>\n                    return \"unsuccessful\";<br \/>\n                    break;<br \/>\n                    case 300:<br \/>\n                    return \"error found\";<br \/>\n                    break;<br \/>\n                    default:<br \/>\n                    return \"undefined status\";<br \/>\n                }<br \/>\n            return match($expcode)<br \/>\n                {<br \/>\n                    100  \t=>    \t\"successful\";<br \/>\n                    200  \t=>    \t\"unsuccessful\";<br \/>\n                    300  \t=>    \t\"error found\";<br \/>\n                    default    => \"undefined status\";<br \/>\n                }<br \/>\n        }<br \/>\n}<br \/>\n?><\/code><\/p>\n<h3>Union type<\/h3>\n<p> More than one data type can be declared with the use of pipes to divide them in php8.<br \/>\n<strong>Example:<\/strong><br \/>\n<code>&lt;?php<br \/>\nclass calculation<br \/>\n{<br \/>\n        \tpublic function add(int|string $a, int|string $b): int|string<br \/>\n        \t{<br \/>\n                    \tif(is_integer($a) && is_integer($b))<br \/>\n                    \treturn $a+$b;<br \/>\n                    \tif(is_string($a) && is_string($b))<br \/>\n                    \treturn $a.$b;<br \/>\n        \t}<br \/>\n}<\/code><\/p>\n<h3>Named argument<\/h3>\n<p>Till now a user passes the argument in a method or function that only passes the values that don&#8217;t enter the name. But in the named argument user can enter the name however user no need to remember the sequence.<br \/>\n<strong>Example:<\/strong><\/p>\n<p><code>class Person {<br \/>\n        \tprotected string $name;<br \/>\n        \tprotected int $age;<br \/>\n        \tprotected int $phone;<br \/>\n        \tpublic function setPerson(string $name, int $age, int $phone)<br \/>\n        \t{<br \/>\n                    \t$this->name = $name;<br \/>\n                    \t$this->age = $age;<br \/>\n                    \t$this->phone = $phone;<br \/>\n        \t}<br \/>\n}<br \/>\n$person = new Person();<br \/>\n$person->setPerson(name: 'arrow',age: 25, phone: 36485845);<br \/>\n$person->setPerson(name: age: 25, phone: 36485845, name: 'arrow');<\/code><\/p>\n<h3>Constructor property promotion<\/h3>\n<p>In PHP8 Constructor property promotion are a new feature that allows declaring of the <a href=\"https:\/\/studysection.com\/blog\/class-composition-in-python\/\">class<\/a> properly and constructor assignment from its constructor.<\/p>\n<p><strong>Example:<\/strong><br \/>\n<code>class Person {<\/p>\n<p>        \tpublic function __construct(protected string $name, protected int $age, protected int $phone)<br \/>\n        \t{<br \/>\n        \t}<br \/>\n}<br \/>\n$person =  new Person(name: 'arrow', age: 25, phone: 36485845);<\/code><\/p>\n<h3>Null safe operator<\/h3>\n<p>Using this feature user can process multiple checks in a single line. if any null or error occurs on the left side then the execution of the right side program stopped at that point.<br \/>\n<strong>Example:<\/strong><\/p>\n<p><code><?php\n$email = null;\nif ($session !=null)\n        \t$user = $session->user;<br \/>\nif($user!= null)<br \/>\n        \t$profile= $user->profile;<br \/>\nif($profile!=null)<br \/>\n        \t$email= $profile->email;<br \/>\nreturn email;<br \/>\n$email= $session?->$user?->$profile?->email;<\/code><\/p>\n<p>If any of these(session, user, profile, email) is not available then it will return null and does not throw the <a href=\"https:\/\/webnersolutions.com\/\">exception<\/a>.<\/p>\n<p><small><em>If you have knowledge of financial accounting and you are in search of a good job, financial accounting certification can help you reach your desired goals. StudySection provides Financial accounting certification for beginner level as well as expert level people in the commerce stream. You can appear in the certification exam for free to get certified.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved<\/p>\n","protected":false},"author":1,"featured_media":3557,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[262,600],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>StudySection Blog - What is new in php8 (Features and Improvements)?<\/title>\n<meta name=\"description\" content=\"PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved performance.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"StudySection Blog - What is new in php8 (Features and Improvements)?\" \/>\n<meta property=\"og:description\" content=\"PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved performance.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-27T04:24:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-27T06:33:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/11\/php-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"What is new in PHP8?\",\"datePublished\":\"2020-11-27T04:24:58+00:00\",\"dateModified\":\"2020-11-27T06:33:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/\"},\"wordCount\":438,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"development\",\"php8\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/\",\"url\":\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/\",\"name\":\"StudySection Blog - What is new in php8 (Features and Improvements)?\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2020-11-27T04:24:58+00:00\",\"dateModified\":\"2020-11-27T06:33:13+00:00\",\"description\":\"PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved performance.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is new in PHP8?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"StudySection Blog - What is new in php8 (Features and Improvements)?","description":"PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved performance.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/","og_locale":"en_US","og_type":"article","og_title":"StudySection Blog - What is new in php8 (Features and Improvements)?","og_description":"PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved performance.","og_url":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2020-11-27T04:24:58+00:00","article_modified_time":"2020-11-27T06:33:13+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/11\/php-1.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"What is new in PHP8?","datePublished":"2020-11-27T04:24:58+00:00","dateModified":"2020-11-27T06:33:13+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/"},"wordCount":438,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["development","php8"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/","url":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/","name":"StudySection Blog - What is new in php8 (Features and Improvements)?","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2020-11-27T04:24:58+00:00","dateModified":"2020-11-27T06:33:13+00:00","description":"PHP8 release date is 26 November 2020. It is a new version with some breaking changes, new features, and improved performance.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/what-is-new-in-php8\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/what-is-new-in-php8\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"What is new in PHP8?"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":201,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3556"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=3556"}],"version-history":[{"count":3,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3556\/revisions"}],"predecessor-version":[{"id":3560,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/3556\/revisions\/3560"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/3557"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=3556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=3556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=3556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}