Book description
Discover effective techniques, workarounds, and expert guidance for avoiding situations where your application might break following PHP 8 migration
Key Features
- Get the hang of all the new features introduced in PHP 8
- Learn how to detect potential code breaks and keep your application code running smoothly in PHP 8
- Explore an exciting new trend - asynchronous PHP programming using Swoole and Fibers
Book Description
Thanks to its ease of use, PHP is a highly popular programming language used on over 78% of all web servers connected to the Internet. PHP 8 Programming Tips, Tricks, and Best Practices will help you to get up-to-speed with PHP 8 quickly. The book is intended for any PHP developer who wants to become familiar with the cool new features available in PHP 8, and covers areas where developers might experience backward compatibility issues with their existing code after a PHP 8 update. The book thoroughly explores best practices, and highlights ways in which PHP 8 enforces these practices in a much more rigorous fashion than its earlier versions.
You'll start by exploring new PHP 8 features in the area of object-oriented programming (OOP), followed by enhancements at the procedural level. You'll then learn about potential backward compatible breaks and discover best practices for improving performance. The last chapter of the book gives you insights into PHP async, a revolutionary new way of programming, by providing detailed coverage and examples of asynchronous programming using the Swoole extension and Fibers.
By the end of this PHP book, you'll not only have mastered the new features, but you'll also know exactly what to watch out for when migrating older PHP applications to PHP 8.
What you will learn
- Gain a comprehensive understanding of the new PHP 8 object-oriented features
- Discover new PHP 8 procedural programming enhancements
- Understand improvements in error handling in PHP 8
- Identify potential backward compatibility issues
- Avoid traps due to changes in PHP extensions
- Find out which features have been deprecated and/or removed in PHP 8
- Become well-versed with programming best practices enforced by PHP 8
Who this book is for
This book is for PHP developers at all levels who have experience in PHP 5 or above. If you're just getting started with PHP, you'll find the code examples useful for learning the language. Developers who have worked for a few months on one or more PHP projects will be able to apply the tips and techniques to the code at hand, while those with many years of PHP experience are sure to appreciate the concise coverage of new PHP 8 features.
Table of contents
- PHP 8 Programming Tips, Tricks and Best Practices
- Foreword
- Contributors
- About the author
- About the reviewer
- Preface
- Section 1: PHP 8 Tips
- Chapter 1: Introducing New PHP 8 OOP Features
- Chapter 2: Learning about PHP 8's Functional Additions
- Chapter 3: Taking Advantage of Error-Handling Enhancements
- Chapter 4: Making Direct C-Language Calls
- Section 2: PHP 8 Tricks
- Chapter 5: Discovering Potential OOP Backward-Compatibility Breaks
-
Chapter 6: Understanding PHP 8 Functional Differences
- Technical requirements
- Learning key advanced string handling differences
- Understanding PHP 8 string-to-numeric comparison improvements
- Handling differences in arithmetic, bitwise, and concatenation operations
- Taking advantage of locale independence
- Handling arrays in PHP 8
- Mastering changes in security functions and settings
- Summary
-
Chapter 7: Avoiding Traps When Using PHP 8 Extensions
- Technical requirements
- Understanding the shift from resources to objects
- Learning about changes to XML extensions
- Avoiding problems with the updated mbstring extension
- Dealing with changes to the GD extension
- Discovering changes to the Reflection extension
- Working with other extension gotchas
- Summary
- Chapter 8: Learning about PHP 8's Deprecated or Removed Functionality
- Section 3: PHP 8 Best Practices
-
Chapter 9: Mastering PHP 8 Best Practices
- Technical requirements
-
Discovering method signature changes
- Managing magic method signatures
- Examining Reflection method signature changes
- Dealing with PDO extension signature changes
- Dealing with newly defined static methods
- Working with the static return type
- Extending the use of the ::class constant
- Taking advantage of trailing commas
- Learning about methods that are no longer required
- Working with interfaces and traits
- Dealing with private methods
- Controlling anonymous class usage
- Understanding changes in namespaces
- Summary
- Chapter 10: Improving Performance
-
Chapter 11: Migrating Existing PHP Apps to PHP 8
- Technical requirements
- Understanding development, staging, and production environments
- Learning how to spot BC breaks before a migration
-
Performing the migration
- Step 1 – Review the migration guide
- Step 2 – Make sure the current code works
- Step 3 – Back up everything
- Step 4 – Create a version control branch
- Step 5 – Scan for BC breaks
- Step 6 – Fix incompatibilities
- Step 7 – Repeat steps 5 and 6 as needed
- Step 8 – Commit changes to the repository
- Step 9 – Test in a simulated virtual environment
- Step 10 – Return to step 5 if the test is unsuccessful
- Step 11 – Install PHP 8 on the staging environment
- Step 12 – Test and clone the staging environment to production
- Testing and troubleshooting the migration
- Summary
- Chapter 12: Creating PHP 8 Applications Using Asynchronous Programming
- Other Books You May Enjoy
Product information
- Title: PHP 8 Programming Tips, Tricks and Best Practices
- Author(s):
- Release date: August 2021
- Publisher(s): Packt Publishing
- ISBN: 9781801071871
You might also like
book
PHP 8 Basics: For Programming and Web Development
Take advantage of PHP 8's powerful features to create basic web applications, solve code tests (required …
book
Clean Code in PHP
Practical lessons, examples, and practices from PHP experts on how to take your PHP skills to …
book
Test-Driven Development with PHP 8
A PHP developer's practical guide to planning, writing, and deploying maintainable and extensible software solutions with …
book
Programming PHP, 4th Edition
Why is PHP the most widely used programming language on the web? This updated edition teaches …