Will PHP 7.2 be the minimum required version for WP 6.2?
Tags: php, wordpress, update, news
Published: 2022-12-18 21:23:21

<!-- wp:paragraph -->
<p>Yes, this is real! It seems that <strong>starting from WordPress 6.2 the minimum PHP version required by WP will be 7.2</strong>. The last change in that aspect of the software was made in May 2019, for WordPress 5.2. </p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":2524,"width":450,"height":253,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><a href="https://felipeelia.com.br/wp-content/uploads/2022/12/meme-gatsy.jpg"><img src="https://felipeelia.com.br/wp-content/uploads/2022/12/meme-gatsy.jpg" alt="" class="wp-image-2524" width="450" height="253"/></a></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The update did not happen before because the team set 5% as the maximum threshold of version usage. According to <a href="https://core.trac.wordpress.org/ticket/57345" target="_blank" rel="noreferrer noopener">this ticket</a>, PHP 5.6 usage finally dropped below that. As PHP doesn't have version 6 and versions 7.0 and 7.1 have usage numbers even lower, the minimum version would be bumped to PHP 7.2. The numbers are also available on the <a href="https://wordpress.org/about/stats/" target="_blank" rel="noreferrer noopener">Stats page of WP.org</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><!-- wp:paragraph -->
<p>As of 17 Dec 2022 [...]:<br><br>PHP 5.6 is at 4.99% of all WordPress sites<br>PHP 7.0 is at 2.68%<br>PHP 7.1 is at 1.82%</p>
<!-- /wp:paragraph --><cite><a href="https://core.trac.wordpress.org/ticket/57345" target="_blank" rel="noreferrer noopener">https://core.trac.wordpress.org/ticket/57345</a></cite></blockquote>
<!-- /wp:quote -->

<!-- wp:heading {"align":"center"} -->
<h2 class="wp-block-heading">WordPress and PHP's timeline</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To increase backward compatibility, WordPress adopts a strict policy regarding minimum PHP versions. PHP 5.2, for example, had its final version released in January 2011 but it was supported by WP until 2019.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>PHP 5.6 reached its <a href="https://www.php.net/eol.php" target="_blank" rel="noreferrer noopener">end of life</a> in December 2018 and today, 4 years later, it is still the minimum required version by WordPress. If the change really happens, we will be still behind: <strong>PHP 7.2 saw its last version released in November 2020</strong>, two years ago.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Out of curiosity, while I write this post, the oldest version <a href="https://www.php.net/supported-versions.php" target="_blank" rel="noreferrer noopener">still receiving updates</a> is PHP 8.0, with end-of-life planned for November 2023. The latest version, 8.2, was released this month and will receive security updates until December 2025.</p>
<!-- /wp:paragraph -->

<!-- wp:table {"className":"is-style-stripes"} -->
<figure class="wp-block-table is-style-stripes"><table><thead><tr><th></th><th class="has-text-align-center" data-align="center">PHP End Of Life</th><th class="has-text-align-center" data-align="center">End of Support By WP</th></tr></thead><tbody><tr><td>PHP 5.2</td><td class="has-text-align-center" data-align="center">01/2011</td><td class="has-text-align-center" data-align="center">05/2019 (WP 5.2)</td></tr><tr><td>PHP 5.6</td><td class="has-text-align-center" data-align="center">12/2018</td><td class="has-text-align-center" data-align="center">??/2023 (WP 6.2)</td></tr><tr><td>PHP 7.2</td><td class="has-text-align-center" data-align="center">11/2020</td><td class="has-text-align-center" data-align="center"></td></tr><tr><td>PHP 8.0 (current version)</td><td class="has-text-align-center" data-align="center">11/2023</td><td class="has-text-align-center" data-align="center"></td></tr></tbody></table></figure>
<!-- /wp:table -->

<!-- wp:heading -->
<h2 class="wp-block-heading">What the PHP version changes for WordPress</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Beyond <strong>improvements in security and speed</strong>, changing the PHP version also makes available a set of new features, modernizing the codebase and decreasing the chances of bugs.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You can see the full list of features that would be available in these three links: <a href="https://www.php.net/manual/en/migration70.new-features.php" target="_blank" rel="noreferrer noopener">PHP 7.0</a>, <a href="https://www.php.net/manual/en/migration71.new-features.php" target="_blank" rel="noreferrer noopener">PHP 7.1</a>, and <a href="https://www.php.net/manual/en/migration72.new-features.php" target="_blank" rel="noreferrer noopener">PHP 7.2</a>. Below you can see just <strong>some examples</strong> of what we would get just setting PHP 7.0 as the minimum:</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading">Return type declarations</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Since PHP 7.0 it is possible to declare the type returned by a function or method:</p>
<!-- /wp:paragraph -->

<!-- wp:code {"className":"php"} -->
<pre class="wp-block-code php"><code>function example( array ...$arrays ): array {}</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Although it is common in some other languages, type declarations (for parameters and return) can be something new to some.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The biggest advantage of this feature is <strong>static analysis of code</strong>: even without executing the code, it is possible to identify if <code>example()</code> is being called without expecting an <em>array</em>. If that is the case, the error can be detected and fixed before any other test is executed.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The majority of IDEs already have that function built in nowadays.</p>
<!-- /wp:paragraph -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading">Null coalescing operator (??)</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Instead of writing</p>
<!-- /wp:paragraph -->

<!-- wp:code {"className":"php"} -->
<pre class="wp-block-code php"><code>$username = isset( $_GET&#91;'user'] ) ? $_GET&#91;'user'] : 'nobody';</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>it would be possible to write its simplified version:</p>
<!-- /wp:paragraph -->

<!-- wp:code {"className":"php"} -->
<pre class="wp-block-code php"><code>$username = $_GET&#91;'user'] ?? 'nobody';</code></pre>
<!-- /wp:code -->

<!-- wp:heading {"level":3} -->
<h3 class="wp-block-heading">Spaceship operator (&lt;=&gt;)</h3>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Commonly used for comparison functions, this operator returns -1, 0, or 1 depending on the comparison result.</p>
<!-- /wp:paragraph -->

<!-- wp:code {"className":"php"} -->
<pre class="wp-block-code php"><code>echo 1 &lt;=&gt; 1; // 0
echo 1 &lt;=&gt; 2; // -1
echo 2 &lt;=&gt; 1; // 1</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2 class="wp-block-heading">PHP 8 Compatibility and WordPress Versions</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Keeping compatibility with a so wide range of versions makes things harder. Compatibility with PHP 8 (8.0, 8.1, and 8.2) is <a href="https://make.wordpress.org/core/handbook/references/php-compatibility-and-wordpress-versions/" target="_blank" rel="noreferrer noopener">still in Beta</a>. Will dropping support to PHP 5.6 give enough room to focus on PHP 8.x? Let's hope so!</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>And you, did you already update your PHP site version?</p>
<!-- /wp:paragraph -->