fbpx
indesign logo
ham icon
icon-eye indesign mediaBy InDesign Media | icon-eye indesign mediaNov 25, 2023 | icon-eye indesign media517 Views
icon-eye indesign mediaNov 25, 2023
icon-eye indesign mediaBy InDesign Media

Today, the PHP team unveiled PHP 8.3, introducing features such as typed class constants, a json_validate() function, dynamic retrieval of a class constant, the #[Override] attribute, and several other enhancements.

Typed Class Constants

In PHP 8.2, the ability to declare types for constants (const) was still unavailable, potentially causing confusion or ambiguity regarding the type being handled:

PHP 8.3 is released with typed class constants, a json_validate function, and many more (1)

Here is an example illustrating how typed constants appear in PHP 8.3:

PHP 8.3 is released with typed class constants, a json_validate function, and many more (2)

The json_validate() function

To validate JSON in PHP, you can achieve this by either setting the JSON_THROW_ON_ERROR flag, utilizing json_last_error, or simply checking for null in a json_decode() call:

PHP 8.3 is released with typed class constants, a json_validate function, and many more (3)

Starting from PHP 8.3, you also have the option to validate JSON using the json_validate() function:

PHP 8.3 is released with typed class constants, a json_validate function, and many more (4)

Dynamic class constant fetch

In PHP version 8.2 and later, dynamically retrieving the value of a class constant was only feasible using the constant() function. The following code would lead to a syntax error:

PHP 8.3 is released with typed class constants, a json_validate function, and many more (5)

Starting from PHP 8.3, it is now possible to dynamically access constants from a class.

PHP 8.3 is released with typed class constants, a json_validate function, and many more (6)

Fallback value for environment variables in INI files

One notable enhancement in PHP 8.3 is the ability to set default values when using environment variables to define INI settings. This feature streamlines the specification of Docker defaults, explicitly eliminating the need to declare defaults as ENV blocks in a Dockerfile. This can simplify various use cases.

For instance, let’s consider a scenario where you want to enable the DRUPAL_FPM_PORT ENV variable to configure an INI value for the www FPM pool:

PHP 8.3 is released with typed class constants, a json_validate function, and many more (7)

Previously, the DRUPAL_FPM_PORT had to be explicitly defined without providing a default value. Now, with PHP 8.3, you can employ a syntax that is reminiscent of a bash/shell script, allowing you to do the following:

PHP 8.3 is released with typed class constants, a json_validate function, and many more (8)

Consider including an xdebug.ini file as part of your Dockerfile for development, featuring sensible defaults. This setup allows developers the flexibility to override values according to their preferences.

Fore more documentation and features study visit PHP official documentation

  • facebook
  • Twitter
  • linkedin
  • Pinterest
Newletter Indesign Media
TOOLS

Our Working Platforms

We provide start-ups and major corporations with comprehensive services that include innovative web solutions and expert assistance.

InDesign Media WhatsApp
Home Services
Quote
Portfolio Contact