In this article, we will talk a little about the new features, changes, and improvements coming with the arrival of PHP 8.1, in general, and within the context of Scriptcase. So keep an eye out and come check out everything that’s new.
Released in November 2021, PHP 8.1 came bringing many interesting features that promote significant gains, especially in the areas of security, speed, and performance.
Much more performance!
As has always been happening throughout the versions, PHP 8.1 brought important gains in terms of performance.
Although the PHP virtual machine is already well optimized in general, we notice that there are gradual performance gains over the versions. We can better understand this by analyzing the numbers released on the official launch page.
Perhaps the first thought when analyzing these numbers is that the difference is small, however, if we imagine a scenario where there is an environment that needs to work with thousands or even tens of thousands of requests per second, each performance gain makes a huge difference!
New Features
To get an overview of all the new features, check out the list below:
Yes, I know, it is quite a list. But don’t worry, we will comment and understand each topic. 😉
Let’s start by discussing enumerations, also known as “Enums.” It is used to establish a new type that has a certain fixed and a limited number of possible values. To explain further, from now on, you can use enumerations instead of a set of constants and consequently have a fully ready-to-use validation.
In general terms, the result of having enums built into the language is that you can stop using class constants to indicate the possible values for a function or a method.
Before:
New read-only properties
In version 8.1 PHP now supports read-only properties. A read-only property, as the name implies, cannot be modified or edited after it is initialized. In other words, it is now possible to define immutable properties since their creation.
Before:
First-Class Callable Syntax
PHP, in general, already has a syntax for referencing classes, and now with version 8.1, a first-class Callable Syntax has been added to replace existing encodings using strings and arrays.
In a way, this is extremely useful for constructing references to code dynamically and more cleanly.
After:
News for initializers
Another new feature coming with PHP 8.1 is that it is now possible to use objects as default parameter values, static variables, and global constants, as well as in attribute arguments.
Before:
After:
Pure Intersection Types
Version 8.0 of PHP supported union types, which makes it possible to tell that a variable types A or B. Now in PHP 8.1 it has also added Intersection Types, which allows us to define a variable of type A and B at the same time. Before:
Before:
The never return type
Another interesting new feature is the never return type which comes exactly to tell the PHP virtual machine, as well as the next person that reads the function/method, that the given function will necessarily terminate the PHP process.
In PHP 8.0, it became possible to overwrite class constants. Now in PHP version 8.1, it is also possible to add the final modifier to class constants so that they are never necessarily overwritten.
Before:
After:
Explicit octal numeric notation
Well, it is already common knowledge that in the PHP language, it is permitted to write numbers on different number bases, however, there could be some confusion in the representation of octal numbers because of the prefix. Aiming to solve this problem, a new type of prefix was added in 8.1 to represent these numbers to look easier to identify.
Before:
After:
Fibers or Fibs can be understood as parallelism mechanisms, the goal is to enable the management of interruptions in the execution flow of your code.
Before:
Support for unpacking arrays with key-string
With PHP 7.4, it already became possible to unpack arrays, but string keys were ignored. With PHP 8.1, it is now possible to unpack arrays with string keys.
Before:
PHP 8.1 + Scriptcase
In version 9.8 Scriptcase has been homologated to PHP version 8.1, so we went from version 7.3 directly to 8.1. It will still be possible to use version 9.8 with PHP 7.3. The new PHP was also approved for the production environment, which means that both Scriptcase itself and the applications generated by it will work with PHP 8.1.
The homologation means that everything has been tested and adapted in the Scriptcase environment to work correctly with the new PHP version. As such, developers using Scriptcase will have their projects automatically updated and adapted to PHP version 8.1. The work of manual review and adaptation has been drastically minimized, which guarantees a significant time saving for developers, proving one of the biggest benefits of using the low-code tool.
On the release page of version 9.8, you can see all the steps to import projects from previous versions of Scriptcase to the new version. Within the Scriptcase applications, it is also possible to customize PHP code through events, libraries, blank, control, etc. For these cases, the developer himself will have to revise his codes to make the necessary corrections and a few adaptations. We have also prepared a tutorial explaining how to make these adaptations, click here to access it.
In tests carried out by our development team and also by some customers who participated in the beta testing process, we noted a huge performance gain, both in the Scriptcase environment and in the production environment. In comparisons made with other PHP versions, the performance gain reaches 40%, comparing, for example, with version 7.3, which is the version used by Scriptcase version 9.7.
Besides being faster, it is now possible to use the new PHP options, fix vulnerability problems and optimize connections with the most recent versions of databases, such as MySQL version 8, which had a compatibility problem with version 7.3 used in Scriptcase 9.7.
We also received a lot of positive feedback from our clients who participated in the homologation tests, confirming the performance and security gains.
The migration process to the new environment is simple and highly recommended, and you can count on the full support of the Scriptcase technical team. for more information on how to use Scriptcase 9.8 for PHP 8.1 and complete instructions on how to migrate your projects.
The fact is that PHP 8.1, together with 8.0, is one more successful PHP version, bringing several benefits and important changes to make all the development flow more modern, optimized, safe, and agile.
And following this dynamic, Scriptcase, with this update, demonstrates its concern in keeping up to date, promoting a more modern, safe, and efficient development environment also for those who use the low-code tool in their day-to-day development. The update to PHP 8.1 was, therefore, a very important step since it proves that Scriptcase continues to evolve competitively in the market, along with the technologies on which it is based. From this update to the latest version of PHP, Scriptcase will be able to join the new features released for this language. In other words, there is still a lot of good stuff coming!
If you don’t know Scriptcase yet, schedule a free demo and test it right now.
Read more articles in our blog here.
This content was originally published here.