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 was released on November 26, 2020. 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

  • Pandas: Data analysis with Python
    The Python Data Analysis Library, or Pandas, is built on top of the fast math library NumPy and makes analysis of large volumes of data an easy and efficient experience.
  • Modern Fortran – Part 2

    Fortran 90 was only the start. The next two iterations – 95 and 2003 – pulled Fortran into a new era of programming languages.

  • Data Analysis with Panda

    The Python Data Analysis Library, or Pandas, is built on top of the fast math library NumPy and makes analysis of large volumes of data an easy and efficient experience.

  • Innovations in PowerShell 5
    Windows 10 brings an updated, fifth release of PowerShell that vastly simplifies the task of managing modules and software packages. The scripting language now also handles various formatted output from commands and selection lists.
  • CoffeeScript: A Replacement for JavaScript?

    Through the years, many languages have tried to improve or even replace JavaScript, including CoffeeScript, which runs in all JavaScript Runtime Environments and compiles into JavaScript.

comments powered by Disqus