Posted By: Tony Baird
Last Updated: Wednesday December 18, 2024
We’re happy to announce we now officially support PHP 8.4 on all our cloud shared, reseller and semi-dedicated plans. PHP 8.4 is the latest 8.x series release with many outstanding improvements and new features.
You can switch to PHP 8.4 using our PHP Selector interface, which allows you to change PHP versions and modify extensions and PHP.ini values. Many applications are currently incompatible, but we allow you to switch to an older version easily with a quick button click.
Now, let’s take a quick look at a few of the many new features available in PHP 8.4
Before PHP 8.4:
class Locale
{
public function __construct(string $countryCode)
{
$this->setCountryCode($countryCode);
}
public function setLanguageCode(string $languageCode): void
{
$this->languageCode = $languageCode;
}
public function getCountryCode(): string
{
return $this->countryCode;
}
}
PHP 8.4:
class Locale
{
public string $countryCode
{
set (string $countryCode) {
$this->countryCode = strtoupper($countryCode);
}
}
public function __construct (string $countryCode)
{
$this->countryCode = $countryCode;
}
}
The new DOM API includes standard compliant support for parsing HTML 5 documents:
$dom = Dom\HTMLDocument::createFromString(
<<<'HTML'
<main>
<article>PHP 8.4 is a feature-rich release!</article>
<article class="featured">PHP 8.4 adds new DOM classes that are spec-compliant, keeping the old ones for compatibility.</article>
</main>
HTML,
LIBXML_NOERROR,
);
$node = $dom->querySelector('main > article:last-child');
var_dump($node->classList->contains("featured")); // bool(true)
You can now use the object API for BCMath:
use BcMath\Number;
$num1 = new Number('0.12345');
$num2 = new Number('2');
$result = $num1 + $num2;
echo $result; // '2.12345'
var_dump($num1 > $num2); // false
There are several new array functions to help you manipulate arrays including array_find:
$animal = array_find(
['dog', 'cat', 'cow', 'duck', 'goose'],
static fn (string $value): bool => str_starts_with($value, 'c'),
);
var_dump($animal); // string(3) "cat"
These are just a few of the new features available in PHP 8.4. The complete list of changes is on the PHP 8.4 release page.
If PHP is not your language of choice, do not worry. We are also continually adding new versions of Python, Node.js, and Ruby. These can be selected using their respective application interfaces. As of December 2023, we support the following for PHP, Python, Node.js, and Ruby versions: