PHP 8.4 is coming soon and in this post let's look at what has been announced so far, and what new features you might expect.
When is PHP 8.4 scheduled to be released?
PHP 8.4 is scheduled to be released on November 21, 2024. Before the release it will feature 6 months of pre-release phases going from Alphas, to Betas, to Release Candidates, and then the official release.
New Array Find Functions
PHP 8.4 will come with new array find functions that include:
-
array_find()
-
array_find_key()
-
array_any()
-
array_all()
See our post on the PHP 8.4 Array Find Functions
PHP Property Hooks
Property hooks are inspired by languages like Kotlin, C#, and Swift, and the syntax includes two syntax variants that resemble short and multi-line closures:
class User implements Named
{
private bool $isModified = false;
public function __construct(
private string $first,
private string $last
) {}
public string $fullName {
// Override the "read" action with arbitrary logic.
get => $this->first . " " . $this->last;
// Override the "write" action with arbitrary logic.
set {
[$this->first, $this->last] = explode(' ', $value, 2);
$this->isModified = true;
}
}
}
Property hooks will help remove boilerplate of property getters and setters, allowing a property to define access and updates using hooks.
Check out our post for more details: Property Hooks in PHP 8.4.
new MyClass()->method() without parentheses
Since member access during instantiation was introduced, you must wrap the new MyClass()
call in parentheses, or you'll get a parse error. The proposed syntax would allow you to access constants, properties, and methods without the extra parentheses:
// Wrapping parentheses are required to access class members
$request = (new Request())->withMethod('GET')->withUri('/hello-world');
// PHP Parse error (<= PHP 8.3): syntax error, unexpected token "->"
$request = new Request()->withMethod('GET')->withUri('/hello-world');
This update fixes papercut that makes working with class member access simpler, not having to add surrounding parentheses or using a static constructor method. This syntax change also puts PHP more in alignment with other C languages like Java, C#, and TypeScript, which don't require surrounded parentheses.
Check out our post for more details: Class Instantiation Without Extra Parenthesis in PHP 8.4.
Learn More
You can follow the PHP 8.4 Preparation Tasks on the wiki.
The post A Look at What's Coming to PHP 8.4 appeared first on Laravel News.
Join the Laravel Newsletter to get all the latest Laravel articles like this directly in your inbox.