Lead Image © Maxim Borovkov, 123RF.com

Lead Image © Maxim Borovkov, 123RF.com

New features in PHP 8

Conversion Work

Article from ADMIN 61/2021
By
After about two years of development, version 8 of the popular PHP scripting language has been released. It comes with a number of innovations and ditches some obsolete features

One of the major innovations in PHP is intended to give the scripting language a boost, but it does require some prior knowledge. As of version 5.5, the code to be executed has been stored in a cache provided by the OPcache extension [1]. Thanks to this cache, the interpreter does not have to reread the scripts for every request.

PHP 8 sees OPcache expanded to include a just-in-time (JIT) compiler. This converts parts of the PHP code into native program code, which the processor then executes directly and far faster as a consequence. As a further speed tweak, the generated binary code is also cached. When the PHP code is restarted, PHP 8 simply accesses the precompiled binary code from the cache.

As the first benchmarks by PHP developer Brent Roose show [2], scripts with repetitive or extensive calculations obviously benefit from these changes. When handling individual short requests, the JIT compiler shows its advantages to a far lesser extent.

Abbreviation

The syntax, which has changed slightly in some places in PHP 8, saves developers some typing. For example, the scripting language adds a more powerful and more compact match function to supplement switch. In Listing 1, $flasher is only On if $lever is set to Up or Down. If none of the comparison values before => are correct, the default value applies.

Listing 1

match

$flasher = match ($lever) {
  0 => "Warning_Flasher",
  'Up', 'Down' => "On",
  default =>
...
Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=