Introduction to PHP 8 Tips

Learn tips to improve code quality in terms of readability, reduction of code lines, and prototyping.

This section introduces new features to PHP 8. The chapters discuss object-oriented programming, followed by new things at the functional and extension level. The last chapter in this section covers direct C language prototyping.

Introducing new PHP 8 OOP features

In this chapter, we’re introduced to new PHP: Hypertext Preprocessor 8 (PHP 8) features specific to object-oriented programming (OOP). The chapter features a set of classes that can be used to generate CAPTCHA images (CAPTCHA is an acronym for Completely Automated Public Turing test to tell Computers and Humans Apart), clearly illustrating new PHP 8 features and concepts. This chapter is critical in helping us quickly incorporate new PHP 8 features into our own practice. In doing so, our code will run faster and more efficiently with fewer bugs.

Press + to interact

Learning about PHP 8’s functional additions

This chapter walks us through important additions and enhancements introduced to PHP 8 at the procedural level. The code examples used show new PHP 8 features and techniques to facilitate procedural programming. Mastering the use of the new functions and techniques in this chapter will help us to write faster and cleaner applications. Even though this chapter focuses on commands and functions, all of the techniques are also useful when developing class methods as well.

Press + to interact

Taking advantage of error-handling enhancements

If you’ve been a PHP developer for any length of time, you will have noticed that as the language continues to mature, more safeguards are put into place that ultimately enforce good coding practices. Along these lines, one of the key improvements in PHP 8 is its advanced error-handling capabilities. In this chapter, we will learn which Notices have been upgraded to Warnings and which Warnings have been upgraded to Errors. This chapter gives us an excellent understanding of the background and intent of the security enhancements, allowing us to better control the use of our code. In addition, it’s critical to be aware of error conditions that formerly only generated Warnings but now also generate Errors in order to take measures to prevent our applications from failing following an upgrade to PHP 8.

Press + to interact

Making direct C-language calls

This chapter introduces the Foreign Function Interface (FFI). In this chapter, we will learn what FFI is all about, what it’s good for, and how to use it. This information in this chapter is important for developers interested in rapid custom prototyping using direct C-language calls. In this chapter, not only do we learn about the background behind introducing FFI into the PHP language, but we also learn how to incorporate C-language structures and functions directly into our code. Although—as we will learn—this should not be done to achieve greater speed, it does give us the ability to incorporate any C-language libraries directly into our PHP application. This ability opens the doors to an entire world of functionality hitherto unavailable to PHP.

Press + to interact