Skip links

PHP 8 New Features and Updates

PHP, one of the favorite languages of developers has now come up with new updates and features. PHP is an open-source server-side scripting language used in web development. PHP 8 has major update brings many optimizations and powerful features to the language.

JIT (Just in Time Compiler)

Just In Time (JIT) compiler enhances the performance by caching the interpreted code. JIT may be enabled/disabled at PHP compile-time and at run-time. When JIT is enabled, the native code of PHP files is stored in an additional region of the OPcache.

Union types

PHP 8 supports nullable types that allow the declaration of more than a single argument, return types, and properties. Yet the functions, parameters, and classes should be of the same type declared in the definition. Any arbitrary types can be declared to and for the arguments, return types, and property class.

Match expressions

Match impressions enhances the switch syntax in many ways. When the match expression contain one or many matching conditions it behaves similarly to multiple cascading case keys in a switch block. It permits the assignment of a value in a variable or returns its value without a local variable value.

Named arguments

In PHP 8 the arguments are self-documented and order – independent. They can be passed on to a function based on the specific parameter name instead of its position and omit the optional ones. It is much easier to understand the coding as argument name.

Attributes

PHP Doc annotations are not required to add metadata to the declarations. Attributes are structured metadata available for declaration using PHP native syntax. This is a in-built feature which enhances the performance while simplifying the process of development.

Construct property promotion

Construct property promotion has been introduced to minimize syntax complexity and redundancy. it is possible to declare the visibility and type of your class properties from the constructor and assign the parameters instantly. It reduces boiler plate code to define and initialize properties.

Null safe operator

The null safe operator uses chain of calls to perform the null check, to detect mistypes, and to evaluate the entire chain. In short circuit evaluation, the second operator is evaluated only if the first operator does not evaluate to null.      

Saner  Numeric string

In PHP, strings fall into three categories:

  • Numeric string: The strings containing a number.
  • Leading-numeric string: The strings whose initial characters are numeric strings and remaining are non-numeric.
  • Non-numeric string: strings not falling in neither Numeric Strings and Leading Numeric string.

Leave a comment

This website uses cookies to improve your web experience.