Understanding Changes in Namespaces
Understand the changes in PHP 8 namespace handling by exploring the updated tokenization process. Learn how PHP 8 enables using reserved keywords in namespaces without conflict and exposes bad naming practices such as whitespace in namespaces. This lesson equips you to write better, forward-compatible namespace code following PHP 8 best practices.
The concept of a namespace was introduced in PHP 5.3 as a means of isolating hierarchies of classes. Unfortunately, the original algorithm that was used to parse namespace names had several flaws. In addition to being overly complicated, the way in which namespace and class names were tokenized internally was performed in an inconsistent manner, leading to unexpected errors.
Before we get into the benefits and potential backwards-compatible breaks, let’s have a look at how the namespace tokenization process has changed.
Discovering differences in tokenization
The tokenization process is an important part of the interpretation process and takes place when our PHP code is executed. In the process of ...