{"id":6346,"date":"2019-08-21T10:08:54","date_gmt":"2019-08-21T10:08:54","guid":{"rendered":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?p=6346"},"modified":"2022-02-19T06:47:40","modified_gmt":"2022-02-19T06:47:40","slug":"introduction-to-php-7-4-features-deprecations-and-speed","status":"publish","type":"post","link":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/","title":{"rendered":"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed"},"content":{"rendered":"<p>The next PHP 7 minor version, PHP 7.4 is expected to be released to the General Availability on November 28th, 2019. So, you should learn about the exciting additions and new features that will make PHP faster as well as highly reliable.<\/p>\n<p>Although PHP 7.4 helps in boosting the performance and improving code reliability, PHP 8 will be the actual landmark for PHP performance because of the approval of JIT inclusion.<\/p>\n<p>In this article, you are going to learn about some of the most interesting features and changes being expected with PHP 7.4.<\/p>\n<h3>What\u2019s New in PHP with PHP 7.4?<\/h3>\n<p>This post will cover the changes and features that need to be added to the language with the final release of PHP 7.4:<br \/>\nForget array_merge: Get Spread Operator in Array Expression with PHP 7.4<\/p>\n<p>Argument unpacking is available since PHP 5.6 a syntax for unpacking arrays and Traversables into argument lists.<\/p>\n<p>For unpacking an array or a Traversable, it has to be prepended by \u2026 (3 dots), as below:<\/p>\n<pre class=\"lang:default decode:true \">function test(...$args) { var_dump($args); }\ntest(1, 2, 3);<\/pre>\n<p>Now this PHP 7.4 RFC suggests extending this feature to array definitions:<\/p>\n<pre class=\"lang:default decode:true \">$arr = [...$args];<\/pre>\n<p>The first benefit of Spread Operator in array expression stated is related to performance. In fact, the RFC doc states:<\/p>\n<div class=\"kinbox-prim\">\n<p>Spread operator should perform better than array_merge. This isn\u2019t just because the spread operator is a language structure and array_merge is a function, but also because compile time optimization can be performant for constant arrays.<\/p>\n<\/div>\n<p>Spread operator supports any traversable objects while the <span class=\"code-block-sml\">array_merge<\/span> function supports only arrays and this is the biggest advantages of spread operator.<\/p>\n<p>Check below the example of argument unpacking in array expression:<\/p>\n<pre class=\"lang:default decode:true \">$parts = ['apple', 'pear'];\n$fruits = ['banana', 'orange', ...$parts, 'watermelon'];\nvar_dump($fruits);<\/pre>\n<p>In case, you run this code with in PHP 7.3 or earlier, PHP displays a Parse error:<\/p>\n<pre class=\"lang:default decode:true \">Parse error: syntax error, unexpected '...' (T_ELLIPSIS), expecting ']' in \/app\/spread-operator.php on line 3<\/pre>\n<p>Instead, PHP 7.4 might return an array as below:<\/p>\n<pre class=\"lang:default decode:true \">array(5) {\n\t[0]=&gt;\n\tstring(6) \"banana\"\n\t[1]=&gt;\n\tstring(6) \"orange\"\n\t[2]=&gt;\n\tstring(5) \"apple\"\n\t[3]=&gt;\n\tstring(4) \"pear\"\n\t[4]=&gt;\n\tstring(10) \"watermelon\"\n}<\/pre>\n<p>As per the RFC you can expand the same array multiple times. Furthermore, the Spread Operator syntax can be used everywhere in the array, as normal elements can be added before or after the spread operator. So the following code might work as expected:<\/p>\n<pre class=\"lang:default decode:true \">$arr1 = [1, 2, 3];\n$arr2 = [4, 5, 6];\n$arr3 = [...$arr1, ...$arr2];\n$arr4 = [...$arr1, ...$arr3, 7, 8, 9];<\/pre>\n<p>You can also unpack arrays returned by a function directly into a new array:<\/p>\n<pre class=\"lang:default decode:true \">function buildArray(){\n\treturn ['red', 'green', 'blue'];\n}\n$arr1 = [...buildArray(), 'pink', 'violet', 'yellow'];<\/pre>\n<p>PHP 7.4 displays the output in the following array:<\/p>\n<pre class=\"lang:default decode:true \">array(6) {\n\t[0]=&gt;\n\tstring(3) \"red\"\n\t[1]=&gt;\n\tstring(5) \"green\"\n\t[2]=&gt;\n\tstring(4) \"blue\"\n\t[3]=&gt;\n\tstring(4) \"pink\"\n\t[4]=&gt;\n\tstring(6) \"violet\"\n\t[5]=&gt;\n\tstring(6) \"yellow\"\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>It is also possible to use the generator syntax:<\/p>\n<pre class=\"lang:default decode:true \">function generator() {\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for ($i = 3; $i &lt;= 5; $i++) {\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; yield $i;\n&nbsp; &nbsp; &nbsp; &nbsp;  }\n}\n$arr1 = [0, 1, 2, ...generator()];<\/pre>\n<p>But it isn\u2019t allowed to unpack arrays passed by reference. Check the following example:<\/p>\n<pre class=\"lang:default decode:true \">$arr1 = ['red', 'green', 'blue'];\n$arr2 = [...&amp;$arr1];<\/pre>\n<p>If you try to unpack an array by reference, PHP displays the following Parse error:<\/p>\n<pre class=\"lang:default decode:true\">Parse error: syntax error, unexpected '&amp;' in \/app\/spread-operator.php on line 3<\/pre>\n<p>Well, if the elements of the first array are stored by reference, you will find them in the second array, as well. Here is an example:<\/p>\n<pre class=\"lang:default decode:true \">$arr0 = 'red';\n$arr1 = [&amp;$arr0, 'green', 'blue'];\n$arr2 = ['white', ...$arr1, 'black'];<\/pre>\n<p>And here is what you get with PHP 7.4:<\/p>\n<pre class=\"lang:default decode:true \">array(5) {\n\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[0]=&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string(5) \"white\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[1]=&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;string(3) \"red\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[2]=&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string(5) \"green\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[3]=&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string(4) \"blue\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[4]=&gt;\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string(5) \"black\"\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>The proposal of Spread operator passed with 43 to 1 votes.<\/p>\n<h3>Arrow Functions 2.0 (Short Closures)<\/h3>\n<p>Anonymous functions in PHP are considered to be quite wordy and hard to implement and maintain. Therefore, RFC has proposed to introduce the shorter and clean syntax of the arrow functions (or short closures), that should allow you to clean up your PHP code importantly.<\/p>\n<p>Consider the following example:<\/p>\n<pre class=\"lang:default decode:true \">function cube($n){\nreturn ($n * $n * $n);\n}\n$a = [1, 2, 3, 4, 5];\n$b = array_map('cube', $a);\nprint_r($b);<\/pre>\n<p>PHP 7.4 allows using a more concise syntax, and the function above can be rewritten as below:<\/p>\n<pre class=\"lang:default decode:true \">$a = [1, 2, 3, 4, 5];\n$b = array_map(fn($n) =&gt; $n * $n * $n, $a);\nprint_r($b);<\/pre>\n<p>Currently, anonymous functions (closures) can derive variables mentioned in the parent scope due to the use of language construct, as shown below:<\/p>\n<pre class=\"lang:default decode:true \">$factor = 10;\n$calc = function($num) use($factor){\nreturn $num * $factor;\n};<\/pre>\n<p>But using the PHP 7.4, variables mentioned in the parent scope are completely captured by value (implicit by-value scope binding). So the whole function seen above can be written on a single line:<\/p>\n<pre class=\"lang:default decode:true \">$factor = 10;\n$calc = fn($num) =&gt; $num * $factor;<\/pre>\n<p>You can use the variable mentioned in the parent scope in the arrow function exactly as you used use($var), and it\u2019s not possible to alter a variable from the parent scope.<\/p>\n<p>A great improvement to the language is the new syntax as it enables to build highly readable and maintainable code.<\/p>\n<p>It is also possible to use parameter and return types, variable-length argument lists (variadic functions), default values, we can pass and return by reference, etc. Finally, you can use short closures in class methods and they can use the $this variable similar to regular closures.<\/p>\n<p>This RFC has got the approval with 51 to 8 votes, and so you can expect it to be a part of PHP 7.4 additions.<\/p>\n<h3>Null Coalescing Assignment Operator<\/h3>\n<p>The coalesce operator (??) that is included with PHP 7 is useful when you need to use a ternary operator in conjunction with isset(). If it exists, it returns the first operand and is not NULL. Or else, it returns the second operand. Below is an example:<\/p>\n<pre class=\"lang:default decode:true \">$username = $_GET['user'] ?? \u2018nobody\u2019;<\/pre>\n<p>The working of this code is quite straightforward: it fetches the request parameter and sets a default value if it doesn\u2019t exist. Hope you have got a clear idea about that line, but what if you have longer variable names as in the below example from the RFC?<\/p>\n<pre class=\"lang:default decode:true \">$this-&gt;request-&gt;data['comments']['user_id'] = $this-&gt;request-&gt;data['comments']['user_id'] ?? 'value';<\/pre>\n<p>Ultimately, this code can be a bit difficult to maintain. So, in order to help developers to write more instinctive code, this RFC suggests the introduction of the <strong>null coalescing assignment operator<\/strong> (??=). So, rather than writing the previous code, you can write the following:<\/p>\n<pre class=\"lang:default decode:true \">$this-&gt;request-&gt;data['comments']['user_id'] ??= \u2018value\u2019;<\/pre>\n<p>In case the value of the left-hand parameter is null, then the value of the right-hand parameter is used.<\/p>\n<p>Remember that, while the coalesce operator is a comparison operator, ??= is an assignment operator.<\/p>\n<p>This proposal was approved with 37 to 4 votes.<\/p>\n<h3>Typed Properties 2.0<\/h3>\n<p>With argument type declarations, or type hints, you can specify the type of a variable that is expected to be passed to a function or a class method. Type hints has been available since PHP 5 and you can use them with the object data type since PHP 7.2. In PHP 7.4 the type hinting has enhanced by including the support for first-class property type declarations. Check the basic example below:<\/p>\n<pre class=\"lang:default decode:true \">class User {\npublic int $id;\npublic string $name;\n}<\/pre>\n<p>The exception of void and callable supports all the types:<\/p>\n<pre class=\"lang:default decode:true \">public int $scalarType;\nprotected ClassName $classType;\nprivate ?ClassName $nullableClassType;<\/pre>\n<p>Below is the explanation by RFC about why void and callable are not supported:<\/p>\n<div class=\"kinbox-prim\">\n<p>The void type is not supported, as it is not useful and has unclear semantics.<\/p>\n<\/div>\n<div class=\"kinbox-prim\">\n<p>The callable type is not supported, as its behavior is context dependent.<\/p>\n<\/div>\n<p>So it is safe to use <span class=\"code-block-sml\">bool<\/span>, <span class=\"code-block-sml\">int<\/span>, <span class=\"code-block-sml\">float<\/span>, <span class=\"code-block-sml\">string<\/span>, <span class=\"code-block-sml\">array<\/span>, <span class=\"code-block-sml\">object<\/span>, <span class=\"code-block-sml\">iterable<\/span>, <span class=\"code-block-sml\">self<\/span>, <span class=\"code-block-sml\">parent<\/span>, any class or interface name, and nullable types (?type).<\/p>\n<p>Types can be used on static properties as below:<\/p>\n<pre class=\"lang:default decode:true \">public static iterable $staticProp;<\/pre>\n<p>They are also permitted with the var notation:<\/p>\n<pre class=\"lang:default decode:true \">var bool $flag;<\/pre>\n<p>You can set default property values, which must match the declared property type, but only nullable properties can have a default null value:<\/p>\n<pre class=\"lang:default decode:true \">public string $str = \"foo\";\npublic ?string $nullableStr = null;<\/pre>\n<p>All properties will have the same type applied in a single declaration:<\/p>\n<pre class=\"lang:default decode:true \">public float $x, $y;<\/pre>\n<p>What happens if you make an error on the property type? Check the following code:<\/p>\n<pre class=\"lang:default decode:true \">class User {\npublic int $id;\npublic string $name;\n}\n\n$user = new User;\n$user-&gt;id = 10;\n$user-&gt;name = [];<\/pre>\n<p>In the above code, you declared a string property type, but you set an array as property value. In such a case, you get the below Fatal error:<\/p>\n<pre class=\"lang:default decode:true \">Fatal error: Uncaught TypeError: Typed property User::$name must be string, array used in \/app\/types.php:9<\/pre>\n<p>This RFC has received an approval with 70 to 1 votes.<\/p>\n<h3>Weak References<\/h3>\n<p>PHP 7.4 will introduce the <a href=\"https:\/\/www.php.net\/manual\/en\/class.weakreference.php\" target=\"_blank\" rel=\"nofollow noopener\">WeakReference<\/a> class with this RFC that enables programmers to retain a reference to an object that avoids preventing the object itself from being destroyed.<\/p>\n<p>Using an extention such as <a href=\"https:\/\/www.php.net\/weakreference\" target=\"_blank\" rel=\"nofollow noopener\">pecl-weakref<\/a>, currently PHP supports Weak References. But, the new API is different from the <span class=\"code-block-sml\">WeakRef<\/span> class that is documented.<\/p>\n<p>This RFC received 28 to 5 votes.<\/p>\n<h3>Covariant Returns and Contravariant Parameters<\/h3>\n<p>A property of class hierarchies is called as variants that describe the effect of types of a type constructor on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Subtyping\" target=\"_blank\" rel=\"nofollow noopener\">subtypes<\/a>.<\/p>\n<p>In general, a type constructor can be:<\/p>\n<p>\u2022<strong> Invariant:<\/strong> if the type of the subtype is limited by the type of the super-type.<br \/>\n\u2022 <strong>Covariant:<\/strong> if the ordering of types is prevented (types are ordered from more specific to more generic).<br \/>\n\u2022 <strong>Contravariant:<\/strong> in case the order is reversed (types are ordered from more generic to more specific).<\/p>\n<p>Right now, PHP has mostly invariant parameter and return types but have some exceptions. But RFC has proposed to allow covariance and contravariance on parameter types and return types, along with offering several examples of code.<\/p>\n<p>Below is an example of covariant return type:<\/p>\n<pre class=\"lang:default decode:true \">interface Factory {\nfunction make(): object;\n}\n\nclass UserFactory implements Factory {\nfunction make(): User;\n}<\/pre>\n<p>And here is an example of contravariant parameter type:<\/p>\n<pre class=\"lang:default decode:true \">interface Concatable {\nfunction concat(Iterator $input);\n}\n\nclass Collection implements Concatable {\n\/\/ accepts all iterables, not just Iterator\nfunction concat(iterable $input) {\/* . . . *\/}\n}<\/pre>\n<p>This RFC received votes from 39 to 1.<\/p>\n<h3>Preloading<\/h3>\n<p><a href=\"https:\/\/wiki.php.net\/rfc\/preload\" target=\"_blank\" rel=\"nofollow noopener\">This was proposed<\/a> by Dmitry Stogov and it is expected to bring a significant boost in performance. In preloading, libraries and frameworks are loaded into the <a href=\"https:\/\/www.php.net\/manual\/en\/book.opcache.php\" target=\"_blank\" rel=\"nofollow noopener\">OPCache<\/a> at module initialization.<\/p>\n<p><a href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6348\" src=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png\" alt=\"\" width=\"335\" height=\"323\" srcset=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png 335w, https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min-300x289.png 300w\" sizes=\"auto, (max-width: 335px) 100vw, 335px\" \/><\/a><\/p>\n<p>Below is explanation of how preloading works as per Dmitry:<\/p>\n<div class=\"kinbox-prim\">\n<p>When the server starts up \u2013 prior to running any application code \u2013 you might load a certain set of PHP files into memory \u2013 and make their contents \u201cpermanently available\u201d to all subsequent requests that will be served by that server. Similar to internal entities, all the functions and classes defined in these files will be available to requests out of the box.<\/p>\n<\/div>\n<p>Prior to any application, these files are loaded on server startup and are executed and remain available for any future requests. This helps in improving the performance.<\/p>\n<p>A specific php.ini directive: opcache.preload controls the preloading. A PHP script to be compiled and executed at server start-up is specified by this directive. It is possible to preload additional files by using this file, either including them or via the opcache_compile_file() function.<\/p>\n<p>But there\u2019s a disadvantage. Even, the RFC clearly states:<\/p>\n<div class=\"kinbox-prim\">\n<p>preloaded files remain cached in opcache memory forever. Therefore, if their corresponding source files are modified, they won\u2019t have any effect without another server restart.<\/p>\n<\/div>\n<p>But all the functions mentioned in the preloaded file will be permanently loaded into PHP function and class tables and will stay available for every future request. This will help in enhancing the performance, though these improvements will vary considerably.<\/p>\n<h3>New Custom Object Serialization Mechanism<\/h3>\n<p>This is another proposal approved with a large majority of votes.<\/p>\n<p>Currently, there are two different mechanisms for custom serialization of objects in PHP:<\/p>\n<p>\u2022 The <span class=\"code-block-sml\">__sleep()<\/span> and <span class=\"code-block-sml\">__wakeup()<\/span> magic methods<br \/>\n\u2022 The <span class=\"code-block-sml\">Serializable<\/span> interface<\/p>\n<p>With both these options, there are issues that help in giving rise to complex and unreliable code. The new serialization method should prevent these issues by offering two new magic methods, <span class=\"code-block-sml\">__serialize()<\/span> and <span class=\"code-block-sml\">__unserialize()<\/span>, that combines two existing mechanisms.<\/p>\n<p>This proposal has received 20 to 7 votes.<\/p>\n<h3>Deprecations<\/h3>\n<p>The following functions\/functionalities will be deprecated with PHP 7.4:<\/p>\n<h3>Change the Precedence of the Concatenation Operator<\/h3>\n<p>Today, in PHP the <strong>\u201c+\u201d<\/strong> and <strong>\u201c-\u201d<\/strong> arithmetic operators, and the <strong>\u201c.\u201d<\/strong> string operator are left associative and have the same precedence.<\/p>\n<p>As an example, consider the following line:<\/p>\n<pre class=\"lang:default decode:true \">echo \"sum: \" . $a + $b;<\/pre>\n<p>In PHP 7.3 this code creates the following warning:<\/p>\n<pre class=\"lang:default decode:true \">Warning: A non-numeric value encountered in \/app\/types.php on line 4<\/pre>\n<p>The reason is that the concatenation is evaluated from left to right. It is similar to writing the following code:<\/p>\n<pre class=\"lang:default decode:true \">echo (\"sum: \" . $a) + $b;<\/pre>\n<p><a href=\"https:\/\/wiki.php.net\/rfc\/concatenation_precedence\" target=\"_blank\" rel=\"nofollow noopener\">This RFC<\/a> will help in changing the precedence of operators, giving \u201c.\u201d a lower precedence than \u201c+\u201d and \u201c-\u201d operators, so that additions and subtractions will always be performed prior to the string concatenation. That line of code should be equivalent to the below:<\/p>\n<pre class=\"lang:default decode:true \">echo \"sum: \" . ($a + $b);<\/pre>\n<p>This is a two-step proposal:<\/p>\n<p>\u2022 Starting from version 7.4, PHP should emit a contempt notice while encountering an unparenthesized expression with <strong>\u201c+\u201d, \u201c-\u201d<\/strong> and<strong> \u201c.\u201d<\/strong>.<br \/>\n\u2022 The actual change of precedence of these operators should be added with PHP 8.<\/p>\n<p>Both proposals have been approved with a large majority of votes.<\/p>\n<h3>Deprecate Left-Associative Ternary Operator<\/h3>\n<p>In PHP the ternary operator, unlike many other languages, is left-associative. But this can be confusing for programmers that switch between different languages.<\/p>\n<p>Currently, in PHP the following code is correct:<\/p>\n<pre class=\"lang:default decode:true \">$b = $a == 1 ? 'one' : $a == 2 ? 'two' : $a == 3 ? 'three' : 'other';<\/pre>\n<p>It\u2019s interpreted as:<\/p>\n<pre class=\"lang:default decode:true \">$b = (($a == 1 ? 'one' : $a == 2) ? 'two' : $a == 3) ? 'three' : 'other';<\/pre>\n<p>This can lead to errors as it may not be what you are intending to do. So, RFC has proposed to deprecate and remove the use of left-associativity for ternary operators and force developers to use parentheses.<\/p>\n<p>This is the next two-step proposal:<\/p>\n<p>\u2022 Starting from PHP 7.4, housed ternaries without clear use of parentheses will display a deprecation warning.<br \/>\n\u2022 Starting from PHP 8.0, you might get will be a compile runtime error.<\/p>\n<p>This proposal has been received approved with 35 to 10 votes.<\/p>\n<h3>PHP 7 Performance<\/h3>\n<p>The above numbers are especially discouraging as those come from a performance point of view, as PHP 7 has seen to be significantly faster. Here are a few stats:<\/p>\n<p>\u2022 As per official PHP benchmarks PHP 7 enables the system to run twice as many request per second as compared to the PHP 5.6 at almost half of the latency.<br \/>\n\u2022 According to the PHP performance comparison by Christian Vigh, PHP 5.2 is 400% slower as compared to PHP 7.<br \/>\n\u2022 As per Andrei Avram, PHP 7.4 offers faster execution times and less memory in comparison to PHP 7.3<br \/>\n\u2022 Phoronix also did some early benchmark tests with PHP 7.4 Alpha and found that it was slightly faster than PHP 7.3.<\/p>\n<h3>How to Install and Run PHP 7.4 on Docker?<\/h3>\n<p>Fortunately, you don\u2019t require to manually compile and configure PHP 7.4. In case you already have Docker installed on your system, you simply need to install the unofficial <a href=\"https:\/\/github.com\/devilbox\/docker-php-fpm-7.4\" target=\"_blank\" rel=\"nofollow noopener\">PHP-FPM 7.4 Docker Image <\/a>and run your tests from the command line in few seconds.<\/p>\n<p><a href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/installing-php74-nginx-2-min.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6347\" src=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/installing-php74-nginx-2-min.png\" alt=\"\" width=\"570\" height=\"365\" srcset=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/installing-php74-nginx-2-min.png 570w, https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/installing-php74-nginx-2-min-300x192.png 300w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><\/p>\n<p>In case you want to run your PHP 7.4 code in your browser, you also need to install an Nginx or Apache image. But don\u2019t worry. Just follow the <a href=\"https:\/\/github.com\/devilbox\/docker-php-fpm-7.4#example\" target=\"_blank\" rel=\"nofollow noopener\">developer\u2019s directions<\/a>. You need to simply copy and paste the commands from the Docker Image page to your command line tool, and you\u2019re ready to go.<\/p>\n<h3>Conclusion<\/h3>\n<p>In this post, we covered a good number of changes and additions that we can expect with the release of PHP 7.4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The next PHP 7 minor version, PHP 7.4 is expected to be released to the General Availability on November 28th, 2019. So, you should learn about the exciting additions and new features that will make PHP faster as well as highly reliable. Although PHP 7.4 helps in boosting the performance and improving code reliability, PHP [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[18,951,952],"class_list":["post-6346","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-web-hosting-faq","tag-php","tag-php-7-4","tag-php-new-version"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed<\/title>\n<meta name=\"description\" content=\"The article gives the complete information about PHP 7.4. It includes fetaures deprecations and speed information as compared to the previous PHP versions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed\" \/>\n<meta property=\"og:description\" content=\"The article gives the complete information about PHP 7.4. It includes fetaures deprecations and speed information as compared to the previous PHP versions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting FAQs by MilesWeb\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-21T10:08:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-19T06:47:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png\" \/>\n<meta name=\"author\" content=\"Pallavi Godse\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pallavi Godse\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/\",\"name\":\"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed\",\"isPartOf\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png\",\"datePublished\":\"2019-08-21T10:08:54+00:00\",\"dateModified\":\"2022-02-19T06:47:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945\"},\"description\":\"The article gives the complete information about PHP 7.4. It includes fetaures deprecations and speed information as compared to the previous PHP versions.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#primaryimage\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png\",\"contentUrl\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png\",\"width\":335,\"height\":323},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/\",\"name\":\"Web Hosting FAQs by MilesWeb\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945\",\"name\":\"Pallavi Godse\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g\",\"caption\":\"Pallavi Godse\"},\"description\":\"Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.\",\"url\":\"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/pallavi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed","description":"The article gives the complete information about PHP 7.4. It includes fetaures deprecations and speed information as compared to the previous PHP versions.","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:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/","og_locale":"en_GB","og_type":"article","og_title":"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed","og_description":"The article gives the complete information about PHP 7.4. It includes fetaures deprecations and speed information as compared to the previous PHP versions.","og_url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/","og_site_name":"Web Hosting FAQs by MilesWeb","article_published_time":"2019-08-21T10:08:54+00:00","article_modified_time":"2022-02-19T06:47:40+00:00","og_image":[{"url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png","type":"","width":"","height":""}],"author":"Pallavi Godse","twitter_misc":{"Written by":"Pallavi Godse","Estimated reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/","name":"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed","isPartOf":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#primaryimage"},"image":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#primaryimage"},"thumbnailUrl":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png","datePublished":"2019-08-21T10:08:54+00:00","dateModified":"2022-02-19T06:47:40+00:00","author":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945"},"description":"The article gives the complete information about PHP 7.4. It includes fetaures deprecations and speed information as compared to the previous PHP versions.","breadcrumb":{"@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#primaryimage","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png","contentUrl":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-content\/uploads\/2019\/08\/php-lifecycle-min.png","width":335,"height":323},{"@type":"BreadcrumbList","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/introduction-to-php-7-4-features-deprecations-and-speed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/"},{"@type":"ListItem","position":2,"name":"Introduction to PHP 7.4 \u2013 Features, Deprecations and Speed"}]},{"@type":"WebSite","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#website","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/","name":"Web Hosting FAQs by MilesWeb","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/7e3952607fa9eb4e82fea9f7cad9c945","name":"Pallavi Godse","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eefc9695ea2b2c6e143c9c9919701aaa?s=96&d=blank&r=g","caption":"Pallavi Godse"},"description":"Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.","url":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/author\/pallavi\/"}]}},"views":988,"_links":{"self":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/6346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/comments?post=6346"}],"version-history":[{"count":3,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/6346\/revisions"}],"predecessor-version":[{"id":13785,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/posts\/6346\/revisions\/13785"}],"wp:attachment":[{"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/media?parent=6346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/categories?post=6346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.milesweb.co.uk\/hosting-faqs\/wp-json\/wp\/v2\/tags?post=6346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}