blog

What are the latest features in PHP 8.3?

Share:

PHP 8.3 is set for release on November 23, 2023, bringing a host of enhancements including improvements to readonly classes, the introduction of a new function, updates to recently added classes, stack overflow detection, and more. In this article, we’ll delve into each feature, performance enhancement, modification, and deprecation individually.

Readonly Property Amendments RFC This RFC proposed two changes, with only one being accepted: the ability to reinitialize readonly properties during cloning. While it may appear to be a relatively specific adjustment, it addresses a crucial edge case – enabling the deep cloning of readonly properties by overwriting property values within _ _clone().

Anonymous readonly classes upgrading. Previously, you weren’t able to mark anonymous classes as readonly. That’s fixed in PHP 8.3:

The new json_validate() function. Until now, the sole method for validating the validity of a JSON string was to decode it and check for any potential errors during the process. The recently introduced json_validate() function proves to be advantageous if your sole requirement is to determine if the input is valid JSON. This is because it consumes less memory in comparison to decoding the string.

Randomizer additions. PHP 8.3 added the new Randomizer class. This update brings some small additions:

This method enables you to create a string of a specified length composed of randomly selected bytes from a given string.

getFloat() returns a float between $min and $max. You can define whether $min and $max should be included thanks to the IntervalBoundary enum. Closed means the value is included, while Open means excluded.

Finally, nextFloat() is a shorthand for getFloat(0, 1, IntervalBoundary::ClosedOpen), in other words: it’ll give you a random float between 0 and 1, where 1 is excluded.

Enhanced Error Reporting for unserialize(). In PHP 8.3, there is a significant improvement in error reporting for the unserialize() function. Now, instead of occasionally issuing an E_NOTICE, unserialize() will consistently trigger an E_WARNING when encountering issues during its execution.

Stack Overflow Detection PHP 8.3 introduces two new initialization directives: zend.max_allowed_stack_size and zend.reserved_stack_size. When a program approaches the limit of the call stack, it may now raise an Error if it surpasses the difference between zend.max_allowed_stack_size and zend.reserved_stack_size.

This enhancement is particularly valuable as it prevents stack-overflow-induced segmentation faults, which makes debugging significantly easier. By default, zend.max_allowed_stack_size is set to 0, allowing PHP to automatically determine a suitable value. You can specify -1 to indicate no limit, or a specific byte size. The zend.reserved_stack_size directive defines a ‘buffer zone’ to ensure PHP can still throw an error rather than running out of memory. PHP will assign a reasonable default value for this directive, making it unnecessary to set it manually, unless you encounter particular program-specific edge cases.

Additionally, for fibers, the existing fiber.stack_size directive serves as the maximum allowed stack size.

Subtle yet Significant Changes. Not every modification in PHP goes through the RFC process. In fact, the majority of changes involve maintenance and bug fixes, bypassing the need for an RFC. You can find all these alterations listed in the UPGRADING document. While I’ll highlight some of the most notable ones, it’s advisable to go through the entire list if you want to delve into the minutiae.

  1. When utilizing FFI, C functions with a return type of void now yield null instead of returning FFI\CData:void.
  2. The posix_getrlimit() function now accepts an optional $res parameter for fetching a specific resource limit.
  3. The gc_status() function boasts four new fields: running, protected, full, and buffer_size.
  4. class_alias() now offers support for creating an alias for an internal class.
  5. In the case of mysqli_poll(), a ValueError is now raised if neither the read nor error arguments are provided.
  6. array_pad() is now restricted only by the maximum number of elements an array can hold. Previously, it was limited to adding a maximum of 1,048,576 elements at a time.
  7. New posix functions have been introduced, namely posix_sysconf(), posix_pathconf(), posix_fpathconf(), and posix_eaccess().
  8. Executing proc_get_status() multiple times on POSIX systems will consistently yield the correct value.

Related articles

Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon

get in touch

EVEN IF YOU DON'T YET KNOW WHERE TO START WITH YOUR PROJECT - THIS IS THE PLACE

Drop us a few lines and we'll get back to you within one business day.

Thank you for your inquiry! Someone from our team will contact you shortly.
Where from have you heard about us?
Clutch
GoodFirms
Crunchbase
Googlesearch
LinkedIn
Facebook
Your option
I have read and accepted the Terms & Conditions and Privacy Policy
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
slash icon
slash icon
slash icon
slash icon
slash icon
slash icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon