PHP 8.4 (Beta 3) Is Now Available for Testing on SiteGround Servers
Table of Contents
We are glad to announce that PHP 8.4 (Beta 3) is now available for testing on all SiteGround servers – way ahead of its scheduled official release date on November 21, 2024. Once again, we are among the first companies to provide PHP 8.4 (Beta 3) for testing on our hosting platform. Thanks to our unique PHP server setup, we are able to offer the latest PHP versions for our clients to test safely on their websites hosted with us.
Discover more about the new features that the latest PHP version brings to the table in the next section.
What’s new in PHP 8.4 (Beta 3)
This latest version introduces some very important new features that will improve the PHP development experience even further. Let’s dive into some of the biggest changes that PHP 8.4 (Beta 3) offers:
Property hooks
One of the new features in PHP 8.4 (Beta 3) includes the ability to define property hooks which will eliminate the need for a lot of boilerplate code. This is one of the biggest changes in PHP history. Property hooks will help remove a lot of getters and setters by allowing each property to define its own get and set hooks. What’s more, an exciting addition is that in PHP 8.4 (Beta 3) property hooks can be defined in interfaces.
We can take this pretty standard class for example:
<?php
declare(strict_types=1);
class Website
{
private $domain;
public function __construct(string $domain) {
$this->domain = $domain;
}
public function getDomain(): string {
return $this->domain;
}
public function setDomain(string $domain): void {
if (strlen($domain) === 0) {
throw new ValueError("Domain must be non-empty");
}
$this->domain = $domain;
}
}
As of PHP8.4 (Beta 3) we can use Property Hooks to achieve the same result with the following syntax:
<?php
declare(strict_types=1);
class Website
{
public string $domain {
set {
if (strlen($value) === 0) {
throw new ValueError("Domain must be non-empty");
}
$this->domain = $value;
}
get => $this->domain;
}
public function __construct(string $domain) {
$this->domain = $domain;
}
}
new without additional parentheses
Another new feature that will save lots of boilerplate code is that you don’t have to wrap newly created objects within parentheses anymore in order to be able to chain methods on them.
What’s more, it works not only for methods – you can also chain properties, static methods, constants – basically whatever you want. Bottom line is that the new feature will simplify the syntax and make the code more concise and readable.
Example:
The “class member access on instantiation” feature was introduced in PHP 5.4.0. Since then constants, properties and methods can be accessed on a newly created instance without an intermediate variable, but only if the new expression is wrapped in parentheses:
class Website
{
...
public function getDomain(): string {
return $this->domain;
}
}
// Valid syntax
$myDomain = (new Website('siteground.com'))->getDomain();
// Invalid syntax until PHP8.4
$myDomain = new Website('siteground.com')->getDomain();
New Array functions
Another notable change in PHP is the introduction of several new Array functions. PHP 8.4 introduced several new array functions with callback function:
array_find()
A function that returns the value of the first array element that matched the condition. If none of the elements matched the condition, the function will return `null`.
array_find_key()
Returns the key of the first element for which the callback was true. If none of the elements matched the condition, the function returns `null`.
array_all()
Checks if the callback returns true for all of the array elements
array_any()
Checks the callback returns true for any of the elements of an array.
These new functions make it easier to search and manipulate arrays based on custom conditions which in terms will lead to cleaner and easier to read code.
How to test PHP 8.4 (Beta 3) on SiteGround servers
As a SiteGround client, you can easily test PHP 8.4 (Beta 3) on your website. Simply log in to your Site Tools > Devs > PHP Manager section and you’ll be able to replace the current PHP version used by your site with PHP 8.4 (Beta 3) with a single click.
Please keep in mind that PHP 8.4 (Beta 3) is mostly available for testing purposes and as usual, we strongly advise you not to use it at your production site before its scheduled official release date (November 21, 2024).
If you need to test PHP 8.4 (Beta 3) with your existing site, we recommend that you create a new site for testing and clone your production site into it to test different things. For this purpose, you can use our WordPress Staging tool. While testing, make sure that nothing fails and check your log files to see if any warnings or errors appear. Once you are done testing, you can simply delete that site.
Wrap-up
At SiteGround, we are constantly working to introduce the newest PHP technology ahead of the others. That’s why we are excited to provide our clients with the latest PHP version which brings to the table some big improvements that could significantly enhance the PHP development experience. Take your time to test the new version before the official release date and stay tuned for more updates from the PHP community.
Comments ( 4 )
Thanks! Your comment will be held for moderation and will be shortly published, if it is related to this blog article. Comments for support inquiries or issues will not be published, if you have such please report it through
coconutboy
Thanks for the update. Any ETA on when PHP7 series will stop completely ?
Mila Kanazirska Siteground Team
While there is no estimated timeline for its discontinuation, we strongly advise customers against using PHP 7.3 and lower versions due to discontinued support. We also recommend performing PHP compatibility checks on your sites and upgrading to a higher PHP version or selecting the Managed PHP option.
Dom
Thank you Daniel for this great announcement. I think it would be best - to ensure SG does not risk to misguide anyone - to show, in SG Site Tools > Devs > PHP Manager > PHP Version - that the available version is 8.4 (Beta 3) instead of showing 8.4.0... I mean 8.4.0 will be the official release 21st Nov, and from your option of 8.4 (Beta 3) August 15, 2024, there will be another 6 RC versions prior the official 8.4.0... I have no idea of differences between alpha versions 1-2-3, beta versions 1-2-3, and RC versions 1-2-3-4-5-6, but I think SG should display what exact PHP version we would be using. Thanks and regards, Dom
Mila Kanazirska Siteground Team
Thank you for your precise input, Dom. As mentioned in the article, PHP 8.4 is currently in its Beta 3 version. We rely on the assumption that individuals who select the Manual PHP option, thereby managing their own PHP version, possess the necessary familiarity with it. For others, we consistently recommend opting for Managed PHP, where our developers handle version updates on their behalf. We appreciate your suggestion and will consider it for future discussions.
Start discussion
Thanks! Your comment will be held for moderation and will be shortly published, if it is related to this blog article. Comments for support inquiries or issues will not be published, if you have such please report it through