What’s New in PHP 8.3 – Key Highlights and Features

  • PHP MySQL Development Services

  • Published On January 12, 2024

Featured Image

PHP has long held a reputation for evolving constantly and meeting all market demands effectively. As one of the world’s most prominent web development languages, PHP is now ready to set expectations even higher with the latest PHP 8.3. 

What's New in PHP 8.3 - Key Highlights and Features

This latest release strives to help developers enhance app performance, refine code quality, and transform development workflows.  But there is a lot more going on with this open-source project, and this article will explore every granular detail of the PHP 8.3 release notes. Let’s dive in!

Introduction to PHP 8.3: A Revolutionary Leap or Evolutionary Step?

PHP 8.3 was released on the 23rd of November, 2023. Since then, the release has been tested through three alpha releases, three beta, and six release candidates. 

What’s New in PHP 8.3?

PHP 8.3 is one of the most significant releases that brings many new features and functionalities. Some of the most notable PHP 8.3 features include the specification of types for class constants. This made it easier to clone any read-only properties and add more options related to randomization.    

Besides, the release also incorporated other enhancements that help enhance the efficiency, fix bugs, and more. For now, let’s start with PHP 8.3 new features explained. 

Here’s an overview of the latest additions that garnered the most attention from the public:    

Typed Class Constants 

In earlier versions of PHP, developers could not declare the type of the constant but were assigned a specific value, which also determined the type. This was an inheritance-based implication that prevented developers from changing the type of the constant when used in abstract classes, interfaces, or child classes.   

Thankfully, things have changed with the PHP 8.3 new features, as developers can now easily specify class constant types. This includes constants in traits, enums, and even in interfaces, helping ensure one sticks to the right type when declaring constants. As a result, the chances of any unintended changes become very low, ensuring a fruitful and effective development.    

Deep Cloning of Read-Only Properties

Another significant enhancement in the PHP 8.3 release is the ability to deep-clone read-only properties. The PHP 8.1 release allowed developers to declare individual class properties as read-only. Then came the PHP 8.2 release that allowed one to assign the same attribute to an entire class. But even these enhancements weren’t enough for developers as constraints when working with classes became a significant issue.   

PHP 8.3 addresses this issue more effectively by allowing read-only properties to be reinitialized while cloning. This allows developers to reinitialize an instance of a class with read-only properties within the clone magic method. This also includes functions invoked from within the class.

PHP 8.3 New Features And Benefits 

Code Game with PHP 8.3's Cutting-Edge Features and Benefits

Performance Enhancements in PHP 8.3 Development 

The current PHP 8.3 features include a slew of significant performance changes that make it an even more appealing option for many. Among the most well-known of these upgrades are:

  • JIT (Just-In-Time) Compilation 

PHP JIT is implemented as a nearly separate component of OPcache. It may be enabled or disabled both during PHP compilation and during runtime. 

  • Improved Object Creation and Memory Management

The latest version of PHP 8.3 allows simplified object creation for its users. It also allows users to better manage the memory of their CMS.

  • Enhanced Garbage Collection

The gc_status() method is a brand-new feature of PHP’s Garbage Collection system. It offers extensive information on the garbage collector’s status, such as collection cycles, collection statistics, and memory use. 

  • Optimized Array Handling

The optimized array handling feature of PHP 8.3 now allows users to better manage a varied range of arrays and simplify their overall operation. 

  • Read-only Properties

Within the magic __clone function in PHP 8.3, read-only attributes can be updated once. Furthermore, read-only classes can now be reinitialized after cloning. Non-read-only classes can also extend read-only classes in the PHP 8.3 changelog.

JIT (Just-In-Time) Compilation

Opcodes, even if they are low-level intermediate representations, must nonetheless be compiled into machine code. JIT “doesn’t introduce any additional IR (Intermediate Representation) form,” but instead generates native code straight from PHP byte-code using DynASM (Dynamic Assembler for Code Generation Engines).

JIT, in a nutshell, converts the hot bits of the intermediate code into machine code. By avoiding compilation, it would be possible to achieve significant gains in speed and memory utilization.

The advantages of using a JIT compiler are:

  • Significantly improved numerical coding performance.
  • Performance is slightly improved for “typical” PHP web application code.
  • The ability to migrate more code from C to PHP since PHP is now sufficiently fast.”

So, while JIT will not significantly increase WordPress speed, it will take PHP to the next level, making it a language in which many functions can now be written directly.

User-Friendly Improvements and Features:

UX operations make up the core of any website and PHP has come up with some unique improvements to maximize operations in web development. The PHP 8.3 update features are:

Typed Class Constants

We could define types for class properties since PHP 7.4. Despite various changes to PHP type over the years, it hasn’t yet been extended to constants — until now.

In PHP 8.3, class constants — including interface, trait, and enum constants — may be typed, making it less likely that developers would deviate from the idea behind a constant’s initial declaration.

Here’s a simple interface example:

// Legal:

interface ConstTest {

    // Declared type and value are both strings

    const string VERSION = “PHP 8.3”;

}

// Illegal:

interface ConstTest {

    // Type and value mismatch in this initial declaration

    const float VERSION = “PHP 8.3”;

}

Working with classes derived from the base declarations reveals the true value of those typed class constants. While a child class can regularly provide a new value to a constant, PHP 8.3 can assist in preventing this from happening by mistakenly altering its type, rendering it incompatible with the initial declaration:

class ConstTest {

 const string VERSION = “PHP 8.2”;

}

class MyConstTest extends ConstTest {

    // Legal:

    // It’s OK to change the value of VERSION here

    const string VERSION = “PHP 8.3”;

    // Illegal:

    // Type must be declared if it was specified in the base class

    const VERSION = “PHP 8.3”;

    // Illegal:

    // In this case, we can’t change the type declared in the 

    // base class, even if the new type and its value are compatible.

    const float VERSION = 8.3;

}

Keep in mind that while “narrowing” several types or utilizing an otherwise compatible type, the type allocated to a class constant might change.

A New json_validate() Function

When working with JSON-encoded data, it’s useful to know if the payload is syntactically correct before doing anything with it.

In prior PHP versions, developers utilized the json_decode() function and checked for problems as it attempted to convert JSON data into associative arrays or objects. The new json_validate() method in PHP 8.3 does error checking without consuming all of the RAM necessary to construct such array or object structures.

Deep Cloning of read-only Properties

PHP 8.1 introduced the option to specify specific class attributes as read-only. The ability to apply the attribute to an entire class was introduced in PHP 8.2. However, many developers felt that the limits imposed while dealing with classes that included such characteristics hampered productive programming.

Two ideas were proposed in an RFC for altering read-only behavior:

  • Allow non-read-only classes to extend read-only classes.
  • Allow read-only properties to be reinitialized when cloning.

It is the second suggestion that has been accepted into PHP 8.3. The new technique enables the reinitialization of instances of a class with read-only attributes within the __clone magic method (even via methods executed from within __clone).

Here’s an example of how the code works:

class Foo {

    public function __construct(

        public readonly DateTime $bar,

        public readonly DateTime $baz

    ) {}

    public function __clone() {

        // $bar will get a new DateTime when clone is invoked

        $this->bar = clone $this->bar; 

        // And this function will be called

        $this->cloneBaz();

    }

    private function cloneBaz() {

       // This is legal when called from within __clone

        unset($this->baz); 

    }

}

$foo = new Foo(new DateTime(), new DateTime());

$foo2 = clone $foo;

New #[\Override] Attribute

When programmers create interfaces in PHP, they offer precise functionality for the methods defined in those interfaces. When creating a class instance, programmers have the option to override a parent method by creating an alternate version in the child, with the same name and a comparable signature.

One issue is that programmers may mistakenly believe they are implementing an overriding parent function or interface method. They might be producing a new beast because of a mistake in the name of the child-class function or because methods in the parent code have been deleted or renamed.

The #[Override] property now allows coding with PHP 8.3 to assist programmers in indicating that a method must have some lineage inside the code.

Dynamic Fetching of Class Constants and Enum Members

Unlike other PHP code properties, obtaining class constants and Enum members with variable names has proven a bit tricky. Before PHP 8.3, you might have done something like this with the constant() function:

class MyClass {

    public const THE_CONST = 9;

}

enum MyEnum: int {

    case FirstMember = 9;

    case SecondMember = 10;

}

$constantName = ‘THE_CONST’;

$memberName = ‘FirstMember’;

echo constant(‘MyClass::’ . $constantName);

echo constant(‘MyEnum::’ . $memberName)->value;

Using the same class and Enum definitions as before, you can now achieve the same outcome with PHP 8.3’s dynamic fetching of constants, as seen below:

$constantName = ‘THE_CONST’;

$memberName = ‘FirstMember’;

echo MyClass::{$constantName};

echo MyEnum::{$memberName}->value;

New getBytesFromString() Method

Have you ever desired to produce random strings from a predefined set of characters? You can accomplish that simply today using the Random extension’s getBytesFromString() function, which was added in PHP 8.3.

This new technique is straightforward: you provide a string of characters as input and indicate how many of them you wish to utilize. The procedure will then randomly choose bytes from the string until it meets the desired length.

New getFloat() and nextFloat() Methods

PHP 8.3 adds two new methods for generating random float values to the Random extension: getFloat() and nextFloat().

After the lowest and maximum values, the getFloat() function accepts a third input. Using a RandomIntervalBoundary Enum, you may determine whether the function can return the min and max values.

Here are the guidelines:

  • IntervalBoundary::ClosedOpen: min but not max may be returned
  • IntervalBoundary::OpenOpen: neither the minimum nor the maximum may be returned.
  • IntervalBoundary::ClosedClosed: both the minimum and maximum values may be returned.
  • IntervalBoundary::OpenClosed: min may not be returned; max may be returned.

When getFloat() is used without an Enum as the third parameter, the default is IntervalBoundary::ClosedOpen.

The description for the new function has a handy example that creates random latitude and longitude coordinates, where latitudes can contain -90 and 90 but longitudes cannot include both -180 and 180 (since they are the same):

$rando = new Random\Randomizer();

printf(

    “Lat: %+.6f Long: %+.6f”,

    $rando->getFloat(-90, 90, \Random\IntervalBoundary::ClosedClosed),

    // -180 will not be used 

    $rando->getFloat(-180, 180, \Random\IntervalBoundary::OpenClosed),

);

The new nextFloat() function is effectively the same as getting a random number between 0 and less than 1 with getFloat():

$rando = new Random\Randomizer();

$rando->nextFloat(); // 0.3767414902847

Security Features

PHP 8.3 will have fallback value support for handling PHP INI Environment variables. To expand the INI Environment variable replacement, use the ‘:-‘ sign to define a fallback value. When an environment variable is not set, the provided fallback value is utilized. Let’s have a look at some of the benefits of this service:

  • Nested Fallback Values: The fallback technique allows environment variables to be used as backup values. As a result, it supports layered fallbacks.
  • PHP Constants as Fallbacks: PHP constants can be used as a fallback value in PHP INI settings that can be changed during runtime.
  • Type Coercion: PHP coerces fallback values that adhere to the same constraints as ordinary string literal configuration variables. “True” is forced to “1” and “false” to an empty string (“”).
  • Security Considerations: You should exercise caution while processing user-supplied INI data since this syntax supports PHP constants. To disable PHP’s constant replacement and environment variables when parsing, use the INI_SCANNER_RAW setting.
  • Supported Functions: This syntax is supported by all PHP functions that deal with INI variables. Parse_ini_file(), Get_cfg_var(), parse_ini_string(), ini_get(), ini_get_all(), and ini_set(), are some of these methods.
  • Version Compatibility: This syntax is not supported by PHP 8.2 and earlier versions. A user-land INI parser, on the other hand, may utilize the values with the $FOO:-BAR syntax to simulate its functionality.
Is Your Website Stuck in the Past? Upgrade to PHP 8.3 for a Modern Boost

Read more: Enhancing the PHP Development Experience with PhpStorm 2023.2

PHP 8.3: Powering Up Developers and Websites

PHP 8.3 release comes with many features that benefit both developers and websites in unique ways. So, let’s explore these benefits in granular detail for a more comprehensive understanding.  

how php 8.3 empowers developers and enhances websites

For Developers:   

Efficiency Unleashed

Efficiency has always been one of the most important considerations for developers and PHP has always made every attempt to get things right here. Even the PHP 8.3 release has many such enhancements focusing on improving performance. This has helped developers enhance operational efficiency without compromising on quality.     

Performance Champion

PHP 8.3 release has many performance enhancements that help developers in many different ways. For instance, optimizing with the read-only properties, enhanced object creation and memory management, and optimized array handling are some of the most noted of these enhancements.   

Security Guardian

Security is one of the most important considerations with cyber-attacks becoming more and more evident by the day. PHP 8.3 has left no stone on this front with advanced security features that ensure unmatched protection from adverse vulnerabilities. This ensures your data remains secure while you focus on enhancing the project.        

Future-Proof Code

Coding is an evolving process where better codes replace the existing ones almost regularly to drive and support more advancements. With that in mind, the PHP 8.3 release allows developers to future-proof their codes and foster sustained evolution. This offers unmatched flexibility in terms of making relevant changes based on the evolving needs and requirements of the market.   

For Websites:

Speed Demon

Speed is one of the most important factors that influences a website’s SEO performance and overall user experience. But this is no concern considering the PHP 8.3 release has specific enhancements that ensure your websites have optimal speed. You can easily optimize every specific element to ensure nothing slows your website down. 

SEO Superstar

Every website needs to ace the SEO ranks to drive any tangible results with its offers. The PHP 8.3 release offers a plethora of different features that help enhance a website’s SEO performance. This helps website owners benefit from better SEO performance to drive more traffic and enhance conversion rates.   

Security Fortress

Security is certainly one of the most important aspects of every website and the future of PHP with 8.3 release has offered many features to ensure security. This helps ensure unmatched website security that keeps your and your customer’s essential data safe and secure. This helps build better business credibility and pave the path for growing a loyal client base.   

Modern Appeal

Most customers appreciate modernity and engage more with brands embracing modernity. This is where the PHP 8.3 for beginners release comes with several features to ensure your website has a modern feel and touch. You can use these features to integrate many interactive features and functionalities that help drive better engagement.

Build Secure and Future-Proof Websites with PHP 8.3's Latest Features

PHP 8.3: Deprecations & Changes 

With every new PHP release, some features and functionalities tend to become obsolete making it important to flag them for eventual removal. As these features are deprecated, it is recommended not to use these features as they will generate notices in different logs when used for executing codes.   

So, here are some of the most notable depictions resulting from the PHP 8.3 release:  

  • Adapting to get_class() and get_parent_class() Changes
  • unserialize(): Upgrade E_NOTICE errors to E_WARNING
  • highlight_file and highlight_string output HTML changes
  • Granular DateTime Exceptions

The constant U_MULTIPLE_DECIMAL_SEPARATORS is deprecated and replaced by U_MULTIPLE_DECIMAL_SEPARATORS.

  • Cannot null ReflectionClass::getStaticProperties() anymore.
  • The use of get_class() and get_parent_class() without arguments is deprecated.
  • The MT_RAND_PHP Mt19937 variant is no longer available for use. 
  • The INI settings assert.active, assert.bail, assert.callback, assert.exception, and assert.warning are deprecated.
  • SQLite3 now defaults to using exceptions for error handling

Considerations When Upgrading or Migrating to PHP 8.3

Upgrading or migrating to PHP 8.3 is always a challenging ordeal with so many considerations to remain mindful of. The PHP 8.3 release made way for numerous depracations and changes making it important you ensure thorough examination of the codebase while planning the migration or upgrade. 

Considerations When Upgrading or Migrating to PHP 8.3

It is better to refer to the official guide to make more informed decisions and take action accordingly for a successful migration from PHP 8.2 to PHP 8.3. If you are migrating from older versions you must practice unmatched caution. 

You must ensure effective suite testing with PHP 8.3 in a sandbox environment before making changes to live. It is important you are mindful of these considerations and facilitate seamless migration or upgrade.   

10 Common Issues You Might Encounter When Upgrading to PHP 8.3

Upgrading to the PHP 8.3 allows users to tap into multiple features and functionalities. Once you update your WordPress to the latest version of PHP, you can expect features like: 

10 Common Issues You Might Encounter When Upgrading to PHP 8.3
  • Improved Security
  • Faster speed 
  • Compatibility and future-readiness
  • Support from the PHP team and in the forums
  • Better performance

Before you learn how to upgrade to PHP 8.3, be ready to encounter these issues:

1. Compatibility Challenges

Every time PHP introduces an update, there are a few plugins and themes that are no longer required by WordPress. However, this aspect is easily overlooked by users when trying to update to the latest version of the language

Besides, implementing custome code on an updated PHP version is another common issue faced by website owners. The usage of custom code can sometimes lag proper structuring or inputs, failing to perform. Therefore, ensure that you’ve cross-checked every aspect of your custom code before migrating to the latest PHP version.  

2. Deprecation Warnings 

Some PHP functions and settings are marked for removal with each new edition. These features are no longer encouraged for usage and will issue notifications in numerous logs when they occur in executing code. Therefore, ensure that you have a first-hand idea of all the deprecated features that were removed. 

3. Testing and Troubleshooting

Upgrading to PHP 8.3 requires thorough testing of your website to ensure that it runs seamlessly after the update. While you’re at it, ensure that you test every UI/UX element of your website to ensure smooth operations post the 8.3 update. 

The troubleshooting time is another crucial aspect of upgrading to the PHP 8.3. Depending on the extent of your upgrade and the size of your website, the support might take anywhere between a few hours to days to resolve the issues. 

4. Hosting Provider Support

The support of your hosting provider is another common concern for website owners planning to upgrade to PHP 8.3. Since the latest version of PHP is new to the market, not all hosting providers are ready to provide compatible support to the users. Therefore, website owners planning to upgrade to the latest version must first update their processes and check for compatibility with their hosting providers. 

5. JIT Compilation Considerations

JIT Compilation Considerations

Compiling JIT can be resource-intensive. It requires a necessary blend of the right skills and structuring to get the most out of the update. Therefore, while you’re updating to the latest PHP version, ensure that you’ve carefully evaluated the native codes and run a smooth update on your website. 

6. Third-Party Software

Third Party Software in PHP 8.3

Using third-party software is another external factor when upgrading to the latest version of PHP. If you use third-party software in your website, ensure that you’ve cross-checked its compatibility with the latest version of the website and amplify your operations in the process. 

7. Development Environment Adjustments

Developers will be able to define types for class components in PHP 8.3 syntax changes. Simply expressed, you may describe the sort of value a constant will contain after declaring it in a class. 

Development Environment Adjustments in PHP 8.3

However, before you seek to leverage this feature of the latest update, ensure that you’ve checked different toolchain upgrades and did a brief research on configuration changes. 

8.  Learning Curve

The new features and syntax can be another challenge in moving your website to PHP 8.3. Users new to PHP might take some time adapting, implementing, and leveraging the latest features of the update. 

9. Testing Environment

Don’t jump into launching the website right after the update! Before you launch the website with the latest update, ensure that you’ve replicated the production. This way, you can ensure that your updates are on-point and will add to the core of your operations.  

10. Backup and Rollback Plan

Backup and Rollback Plan

No matter how confident you are with the updates, don’t proceed with your operations without a proper backup and rollback plan. For the safety of your website, create multiple backups of your website and then try moving it to the latest update. This way, you can access your way back to operations if the update goes south. 

Read more: The Need for a PHP Supported Retail Store Development

FAQs

What Security Enhancements Have Been Made in PHP 8.3?

The PHP 8.3 release comes with many different security features but the enhancement in the type class constants is the most notable. This helps enhance type safety and ensures constants are assigned values of the correct type.

Will My Existing Plugins and Themes Be Compatible with PHP 8.3?

Most platforms are compatible with every release of PHP and the PHP 8.3 release is no exception. However, there is no assurance that all the existing plugins will be compatible with the new version.

How Can I Test My Website for Compatibility with PHP 8.3?

You can use the PHPCompabilityWP to test your website’s compatibility with PHP 8.3. You can use the PHP_CodeSniffer command line tool to scan code for warnings and errors.

What Are the Most Common Compatibility Issues Encountered During Upgrades?

Managing the complexities related to plugin and theme compatibility is one of the most common compatibility issues you can encounter during a PHP upgrade.

What Steps Should I Take to Prepare for a Smooth Upgrade to PHP 8.3?

Understanding the deprecations, and changes, and keeping up with all the latest information are some of the steps you should take for a smooth upgrade to PHP 8.3.

What Are the Deprecations in PHP 8.3, and How Will They Affect My Code?

Deprecations in the PHP 8.3 version include:
– Adapting to get_class() and get_parent_class() Changes
– unserialize(): Upgrade E_NOTICE errors to E_WARNING
– highlight_file and highlight_string output HTML changes
– Granular DateTime Exceptions
– The constant U_MULTIPLE_DECIMAL_SEPARATORS is deprecated and replaced by U_MULTIPLE_DECIMAL_SEPARATORS.
– Cannot null ReflectionClass::getStaticProperties() anymore.
– The use of get_class() and get_parent_class() without arguments is deprecated.
– The MT_RAND_PHP Mt19937 variant is no longer available for use.
– The INI settings assert.active, assert.bail, assert.callback, assert.exception, and assert.warning are deprecated.
– SQLite3 now defaults to using exceptions for error handling

How Can I Leverage Union Types to Improve Code Readability and Maintainability?

Using Union Types can help you enhance your code’s readability and maintainability helping you benefit from more flexibility and facilitate seamless scaling as per your need.

What Are the Best Practices for Upgrading to PHP 8.3 in a Production Environment?

Familiarizing yourself with the latest industry standards, using the right tools and applications, and testing your codebase thoroughly are some of the best practices for upgrading to PHP 8.3 in a production environment.

What Considerations Should I Keep in Mind Regarding PHP 8.3 When Working with Popular CMS Platforms Like WordPress or Joomla?

Learning all the latest features and functionalities, understanding deprecations and their impact, and ensuring thorough testing are some of the most important considerations you need to remember when using PHP 8.3 in WordPress or Joomla.

Can You Provide Insights into the Community Support and Developer Ecosystem for PHP 8.3?

PHP is very popular and accessing community support is easy with it as long as you follow PHP blogs, engage with online communities, and attend PHP meetups and conferences. PHP also offers an official guide to help address different issues raised by PHP developers.

How Does PHP 8.3 Handle Errors and Exceptions, and What Improvements Have Been Made in This Regard?

The new json-validate() function in the PHP 8.3 release does an excellent job of checking errors without using all the memory needed to build arrays or object structures.

    Ready for Digital Transformation?

    Ask our team for custom made business growth plan.

    Saumil Kalaria
    About Author
    Saumil Kalaria

    Saumil has been in the digital transformation space for over nine years. He's an expert who offers custom LAMP development solutions across various industries—looking for a reliable expert in LAMP Technologies? Then do get in touch with Saumil today!

    Related Articles

    • What Is PHP Used For?

      It is true that having an online presence for business has become a necessity now-a-days. The moment you think of developing a website you should consider PHP application development company.

    • Why Should Businesses Prefer PHP Web Development Services
      Why Should Businesses Prefer PHP Web Development Services?

      Businesses, be it small or large, having an online presence has become essential. Increasingly, businesses are jumping on the web development bandwagon to grow and flourish the businesses. It has

    • how zend framework 2 can benefit your web application
      How Zend Framework 2 Can Benefit Your Web Application?

      Talking About How Zend Framework 2 Can Benefit Your Web Application? Since its inception, PHP web application development services has been in demand and will always be. Since years, developers