Uniform Variable Syntax
Learn about uniform variable syntax and what new features it provides.
One of the most radical initiatives introduced in PHP 7.0 was an effort at normalizing PHP syntax. The problem with earlier versions of PHP was that, in some cases, operations were parsed from left to right, whereas in other cases, this was done from right to left. This inconsistency was the root cause of a number of programming vulnerabilities and difficulties. As a result, an initiative known as uniform variable syntax was launched by the PHP core development team. But first, let’s define key points that form the uniform variable syntax initiative.
Defining uniform variable syntax
Uniform variable syntax is neither a protocol nor a formal language construct. Rather, it is a guiding principle that strives to ensure all operations are performed in a uniform and consistent manner. Here are some key points from this initiative:
Uniformity in the order and referencing of variables
Uniformity in function calls
Straightening out problems with array dereferencing
Providing the ability to mix function calls and array dereferencing in a single command
How does uniform variable syntax affect PHP 8?
The uniform variable syntax initiative was extremely successful in all versions of PHP7, and the transition was relatively smooth. There were a few areas not upgraded to this standard, however. Accordingly, a new proposal was introduced to address these holdouts. Uniformity has been introduced to the following in PHP 8:
Dereferencing interpolated strings
Inconsistent dereferencing of magic constants
Consistency in class-constant dereferencing
Enhanced expression support for
new
andinstanceof
Before getting into examples of each of these areas, we must first define what is meant by dereferencing.
Defining dereferencing
Dereferencing is the process of extracting the value of an array element or object property. It also refers to the process of obtaining the return value for an object method or function call. Here’s a simple example:
Get hands-on with 1200+ tech skills courses.