Introduction to PHP 8 Tricks
Explore how to identify and address backward-compatibility issues when migrating to PHP 8. Understand new object-oriented features, functional differences, extension updates, and removed functionalities to ensure your code works reliably and securely after upgrading.
In this section, we are taken into the dark corners of PHP 8: the places where backward-compatibility breaks exist. This part gives us insight into how to avoid problems before migrating an existing application to PHP 8. We will learn what to look for in our existing code that could cause it to stop working after a PHP 8 upgrade. Once we master the topics presented in this part of the course, we will be well-equipped to modify existing code in such a manner that it continues to function normally following a PHP 8 upgrade.
The following chapters are included in this section:
Discovering Potential OOP Backward-Compatibility Breaks
In this chapter, we will be introduced to new PHP 8 features specific to OOP. The chapter provides us with plenty of short code examples that clearly illustrate the new features and concepts. This chapter is critical in helping us quickly take advantage of the power of PHP 8 as we adapt the code examples for our own practice. The focus of this chapter is on situations where object-oriented code might break after a PHP 8 migration.
Understanding PHP 8 Functional Differences
In this chapter, we will learn about potential backward-compatible breaks at the PHP 8 command, or functional, level. This chapter presents important information that highlights potential pitfalls when migrating existing code to PHP 8. The information presented in this chapter is critical to know so that we can produce reliable PHP code. After working through the concepts in this chapter, we’ll be in a better position to write code that produces precise results and avoids inconsistencies.
Avoiding Traps When Using PHP 8 Extensions
One of the main strengths of the PHP language is its extensions. Changes to the PHP language introduced in PHP 8 also require extension development teams to update their extensions at the same time. In this chapter, we will learn which major changes to extensions have been made and how to avoid traps when updating an existing application to PHP 8.
Once we have finished reviewing the sample code and topics presented in this chapter, we will be able to prepare any existing PHP code for migration to PHP 8. In addition to learning about the changes to the various extensions, we will also gain deep insight into their operation. This ability will allow us to make informed decisions when using extensions in PHP 8.
Learning about PHP 8’s Deprecated or Removed Functionality
This chapter walks us through functionality that has been deprecated or removed in PHP 8. This information is extremely important for any developer to know. Any code that uses removed functionality must be rewritten before an upgrade to PHP 8. Likewise, any deprecation is a clear signal that we must rewrite any code that depends upon such functionality or risk problems in the future.
After we have read the material in this chapter and followed the example application code, we can detect and rewrite code that has been deprecated. We can also develop workarounds for functionality that has been removed and learn how to refactor code that uses removed functionality involving extensions. Another important skill we will learn from this chapter is how to improve application security by rewriting code depending on removed functions.