Before we can play around, of course we must first download PHP 8. At the time of this writing, PHP 8 is not yet officially out. As such, we'll tap a custom Homebrew formula to make the installation process as painless as possible. Alternatively, you might consider using Docker or Vagrant to create an isolated environment for testing PHP 8.
First up on the agenda is the new Nullsafe operator. This operator - represented as a question mark - allows you to call a method on the result of any expression if it does not evaluate to
null. It sounds confusing, but it really isn't. Let's have a look.
This next one is a small, but useful addition to PHP 8 that received unanimous support during the voting stage. You now have the ability to use
::class directly on an object. The result will be functionally identical to the result of
get_class(). In PHP 7 and below, this functionality was limited to the class, itself.
It took a global pandemic for PHP to finally add a
str_contains helper function, but it's finally here (along with a few others). In this episode, we'll review
Weak maps are effectively key value stores that allow for garbage collection. You won't reach for these often, but they're nonetheless an important tool to have in your belt.
*Series still in development. Check back often for updates.