Another digital acronym? What a surprise. But don’t roll your eyes just yet.
Because if you know anything about PHP – even more reason if you don’t or your knowledge is byte sized – you really should read on because we’re about to give you a close coding encounter following the launch of a somewhat significant new version, PHP 8.
What is PHP?
PHP is a general-purpose scripting language for building websites – the biggest in fact running right to the core of the world’s most popular content management system WordPress and social media gargantuan Facebook.
According to web technology usage site W3Techs.com, PHP is ‘used by 79.2% of all the websites whose server-side programming language we know’.1
PHP used to stand for Personal Home Page, now it stands for Hypertext Pre-processor. Don’t feel bad for preferring the former.
It’s a server-side scripting language which is embedded in HTML (Hyper Text Markup Language which is the standard for creating web pages) and can play a whole host of roles such as generating dynamic page content, session tracking, collecting form data, sending and receiving cookies and build entire e-commerce sites, to name a few.
What about PHP 8?
PHP 8 – launched in November 2020 – is a pretty hefty update as updates go.
Positively packed with new features, functions and performance improvements – including union types, JIT (just in time), the nullsafe operator, named arguments, non-capturing catches – in other words an awful lot of coding language designed to make PHP more efficient and reliable.
While that’s not for us to worry about with a screen side view, those grafting away at the back end of website development are particularly overjoyed as it gifts them the pot of gold – the tools to write well-structured code.
So, how it has changed and what are its benefits?
8 is definitely the magic number here.
PHP 8 has 8 main new features, some of which we mentioned above:
The new features
Attributes
One of the most debated new features in PHP 8 is attributes, also known as “annotations”.
Attributes replace the docblocks metadata storage declaring metadata for classes, methods, functions, and arguments. Now, attributes can be declared with Syntax #[…].
Fallthrough
If a switch statement doesn’t have a break after each case, it will run to the next case, even if the intention was for the code to break. This allowed switch functions to execute several blocks of code in sequence but was the cause of many bugs.
Match (explained below) enforces an break after each arm and multiple conditions can be commanded with commas separating conditions.
JIT compiler
When PHP is run, it’s assembled into virtual instructions that are executed in a virtual machine. JIT changes this by assembling the code into x86 machine code and then running that code directly on the CPU. This will improve performance on applications that rely heavily on mathematical functions but won’t make much difference for your average web apps.
Match Expressions
Match Expressions intend to solve problems in Switch functionality.
Switch used a type-converting relational operator (==), which often caused bugs. Now, independent of strict_types, Match uses a strict comparison operator (===).
Mixed Types
In recent versions of PHP, it was possible to declare the expected type of input and return data. However, PHP did not always support Types, and this is a problem. In some cases, a Type was omitted or simply forgotten. MixedTypes now tries to solve this problem.
Named Arguments
Named arguments offer more flexibility when calling functions. Instead of calling a function and passing each argument in the order specified by the function, named arguments define a name for each parameter and can be called out of order.
Static Return Type
“The static special class name in PHP refers to the class a method was actually called on, even if the method is inherited. This is known as “late static binding” (LSB). This RFC proposes to make static also usable as a return type (next to the already usable self and parent types).”*
Static can’t be used as part of a parameter in this case, and refers to the class that was called.
Throw expressions
Throw statements are now expressions, enabling it to return a value. This makes throw usable in a wider spectrum of scenarios.
Union Types
Union types announce the type of value expected from an input (schema in some other languages). It’s defined by using a pipe | or pre-defined classes.
Why we’re rolling it out across our client base
After five happy years of PHP 7, it’s a pleasure to cele-PHP 8!
As a web development agency there are a number of reasons why we’re using PHP 8 to get our client sites up to speed – and not just because support for versions 7.1 and 7.2 has ended and version 7.3 will now only receive security fixes support.
For websites using PHP 7.4.x version, support is still available for a few months.
But the sooner websites switch to PHP 8 the sooner they’ll benefit from its latest features – and as a business, brand or organisation, you’ll have peace of mind.
The language update allows for a huge step up in website performance.
Its new features offer more flexibility for developers and it will have a real impact on ramping up site security.
Keeping within the PHP 8 supported range makes website maintenance easier which is essential for keeping your site secure. And if you’re looking for hassle free, website maintenance, that’s actually in our wheelhouse, with bespoke packages available for websites of all sizes.
Time for an upgrade?
Not only is it best practice to upgrade before support for PHP 7 versions runs out, it also makes sense to protect against security vulnerabilities and take advantage of PHP 8’s performance gains.
If you’re looking to update to PHP 8 get in touch with us for a seamless transition by calling 0161 213 9941 or emailing us at: clients@cornerstonedm.co.uk
*https://wiki.php.net/rfc/static_return_type
Jonathan was born to code. Since being knee high to a grasshopper he has been coding and tinkering with all things technical – from websites and computers to mobile phones and Tamagotchis. Prior to joining the team Jonathan spent over 15 years working for nationally renowned clients across the sectors of sport, hospitality, property development […]
Find out more about us