DEV Community

Hikari
Hikari

Posted on

Sneak Peek: Tutorial on Successfully Installing PHP 8.4 on MacOS

According to official announcements, PHP 8.4 is set to be released on November 21, 2024. It will undergo testing through three alpha versions, three beta versions, and six release candidates.

This major update brings a host of optimizations and powerful features to PHP. We're excited to guide you through the most interesting updates and changes that will enable us to write better code and build stronger applications.
Ready to dive in? Let's explore!

What's New in PHP 8.4

1. DOM Extension Now Supports HTML5 in PHP 8.4

The DOM extension in PHP 8.4 just got a significant upgrade with support for HTML5 parsing and serialization. This means no more headaches when dealing with HTML5-specific tags or embedding HTML in JavaScript. Simply use the new DOM\HTMLDocument class, and your HTML5 content will be handled correctly, adhering to modern Web standards.
Here’s how to create an HTML document from a string:

use DOM\HTMLDocument;

$htmlDocument = HTMLDocument::createFromString('<!DOCTYPE html><html><body>Hello, HTML5!</body></html>');
Enter fullscreen mode Exit fullscreen mode

Or from a file:

use DOM\HTMLDocument;

$htmlDocument = HTMLDocument::createFromFile('path/to/your/file.html');
Enter fullscreen mode Exit fullscreen mode

Learn more: PHP RFC: DOM HTML5 Parsing and Serialization

2. Increased Default bcrypt Cost in PHP 8.4

In PHP 8.4, the default encryption cost for bcrypt has been increased to 12. What does this mean?

Bcrypt is a password hashing function used by PHP. It serves as a shield against hackers trying to crack passwords.

The strength of this shield can be adjusted. The higher the setting or "cost", the stronger the shield, as bcrypt is an adaptive function:"Over time, the number of iterations can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power."

Why is this important? Because increasing the bcrypt encryption cost slows down password hashing by a few milliseconds.

Learn more: PHP RFC: Increase Default BCrypt Encryption Cost

3. More Reliable Parsing of Large XML Documents in PHP 8.4

This change addresses potential issues in the ext/xml PHP extension related to parsing large XML documents.

Modifications in libxml2 version 2.7.0 inadvertently broke the parsing of large documents when using the xml_parse() and xml_parse_into_struct() functions, leading to parsing errors.

PHP 8.4 introduces a new parser option to correctly handle these large XML documents and prevent parsing errors, enabling developers to efficiently parse large XML documents without needing complex workarounds.

Learn more: PHP RFC: XML_OPTION_PARSE_HUGE

4. New Multibyte Trimming Functions in PHP 8.4

The mbstring extension in PHP 8.4 now includes three new functions: mb_trim(), mb_ltrim(), and mb_rtrim(). This addition makes trimming strings with multibyte characters easier, improving upon the previous usage of regex with preg_replace().

The new functions handle spaces and other characters in a multibyte-safe manner. The default behavior removes a predefined set of characters, including various types of whitespace characters, some of which are not typically covered by the \s regex.

Here are the functions and their default behaviors in PHP 8.4:

  • mb_trim($string, $characters): Trims characters from both ends of a string.
  • mb_ltrim($string, $characters): Trims characters from the beginning (left side) of a string.
  • mb_rtrim($string, $characters): Trims characters from the end (right side) of a string.

By default, $characters include various whitespace characters, but not all possible Unicode characters due to storage and compatibility issues.

Learn more: PHP RFC: Multibyte Trimming Functions mb_trim, mb_ltrim, and mb_rtrim

5. IMAP Module Moved to PECL

In PHP 8.4, the IMAP module is no longer compiled into configure and has been moved to PECL. Developers needing the IMAP module will have to compile it separately.

How to Install PHP 8.4 on MacOS

As of now, PHP 8.4 has not yet been released, but ServBay has already integrated the latest PHP 8.4 Dev version, including the IMAP module. Developers can directly download and install it from their official website https://www.servbay.com in just 3 minutes, setting up a PHP development environment effortlessly.

Image description

(ServBay offers a wide range of PHP versions, from PHP 5.6 to the latest PHP 8.4 Dev, ensuring developers can always use their desired development environment)

Image description

Learn More

Conclusion

PHP 8.4 brings a plethora of exciting new features and improvements, enabling developers to write cleaner, faster, and more expressive code. However, upgrading to PHP 8.4 requires caution. Consider backward compatibility changes and thoroughly test your code to ensure a smooth transition. By using ServBay, you can explore the new features of PHP 8.4 without impacting your development environment and carefully plan your upgrade process. You can unleash the full potential of PHP 8.4 and elevate your development skills to new heights.

Top comments (0)