About this chapter
PHP keeps getting better every year. This chapter walks you through the most useful features added in PHP 8.4 (released in late 2024) and PHP 8.5 (released in late 2025). These are the tools that make everyday code shorter, safer, and easier to read.
You have already learned the core of the language - variables, arrays, functions, and object-oriented programming. This chapter builds on that. Most examples here use classes and objects, so if anything looks unfamiliar, revisit the object-oriented programming chapter first.
What you'll learn in this chapter
- How to check which PHP version you're running, and why 8.4 and 8.5 matter.
- Writing
new User()->save()without the extra parentheses (PHP 8.4). -
Property hooks - putting
get/setlogic directly on a property (PHP 8.4). - Asymmetric visibility - a property that is public to read but private to write (PHP 8.4).
- New array helpers:
array_find,array_any,array_all, andarray_find_key(PHP 8.4). - The
#[\Deprecated]attribute for marking old code (PHP 8.4). - The pipe operator
|>for chaining functions left to right (PHP 8.5). -
array_first()andarray_last()for grabbing the ends of an array (PHP 8.5). - The
#[\NoDiscard]attribute that warns when you ignore a return value (PHP 8.5).
A note before you start
You don't need the newest PHP to keep learning - everything from the earlier chapters runs on PHP 8.0 and up. But if you can install PHP 8.4 or 8.5, you'll be able to run every example here yourself. The first lesson shows you how to check.
Each feature is small and self-contained, so you can read the lessons in any order. Let's start by making sure you know which PHP you have.
Lessons from courses
- 1 Checking Your PHP Version and What's New in 8.4 and 8.5 Learn how to check your PHP version from the command line and in code, and get a quick overview of what changed in PHP 8.4 and 8.5.
- 2 Creating Objects Without Extra Parentheses in PHP 8.4 PHP 8.4 lets you call a method on a freshly created object without wrapping new in parentheses. Learn the new syntax with clear before-and-after examples.
- 3 Property Hooks in PHP 8.4: get and set on a Property Learn PHP 8.4 property hooks: add get and set logic directly to a property, create virtual properties, and replace one-line getters and setters.
- 4 Asymmetric Visibility in PHP 8.4: Public to Read, Private to Write Learn PHP 8.4 asymmetric visibility: make a property readable from anywhere but writable only inside the class using public private(set), with examples.
- 5 New Array Functions in PHP 8.4: array_find, array_any, array_all Learn PHP 8.4's new array functions: array_find, array_find_key, array_any, and array_all - cleaner ways to search arrays with a callback.
- 6 The #[\Deprecated] Attribute in PHP 8.4 Learn the PHP 8.4 #[Deprecated] attribute to mark functions, methods, and constants as outdated so PHP warns anyone who still uses them.
- 7 The Pipe Operator in PHP 8.5: Chaining Functions Left to Right Learn the PHP 8.5 pipe operator |> - pass a value through a series of functions left to right instead of nesting calls inside out.
- 8 array_first() and array_last() in PHP 8.5 Learn PHP 8.5's array_first() and array_last() functions to get the first and last value of an array cleanly, even with non-numeric keys.
- 9 The #[\NoDiscard] Attribute in PHP 8.5 Learn the PHP 8.5 #[NoDiscard] attribute that warns when you call a function but ignore its return value - catching a whole class of silent bugs.