Sitemap

Embracing Change: Preparing for PHP 8.3

2 min readNov 29, 2023
Photo by Ben Griffiths on Unsplash

PHP 8.3 has landed, introducing a host of updates and changes. While change can be daunting, this will help you navigate through the new landscape of PHP 8.3 with ease

Navigating Through Deprecations

Why Are Deprecations Your New Best Friends?

Deprecations are like helpful road signs pointing toward future changes. In PHP 8.3, these signs are mostly about tidying up for PHP 9. Encountering a deprecation? Often, a simple composer update is your quick fix. If not, a few code tweaks should do the trick.

A Few Key Deprecations to Note:

  • Increment and Decrement Operators: Using ++ or -- on non-numeric strings is a no-no.
$word = "apple";
$word++; // PHP says, "Let's not."
  • Class Functions Without Arguments: get_class() or get_parent_class() will need arguments. No more free rides!
echo get_class(); // PHP 8.3 says, "I need more details!"
  • FFI API Changes: You can’t call cast, new, or type statically anymore. Keep an eye on those function signatures.
  • SQLite Library Update: Warnings will soon be exceptions. The function enableExceptions(false) is now deprecated.

Bracing for Breaking Changes

Breaking changes might sound scary like someone dropped your favorite mug. But often, they’re just necessary steps to make PHP better.

Some Breaking Changes to Be Aware Of:

  • proc_get_status Fix: Fixed an issue with returning wrong values on posix systems.
$status = proc_get_status(); // Old way
$status = proc_get_status($process); // New and improved
  • Trait Static Properties: They now behave differently, redefining properties inherited from parent classes.
  • Array Negative Index: Before, adding an item to an array with a negative index did something weird. Now, PHP handles it more logically. If you add an item to an array with a negative index, it no longer defaults to index zero.
$array = [];
$array[-1] = "old value";
$array[] = "new value"; // PHP now handles this better
  • Memory Overflow Prevention: PHP now throws an error if it’s close to a memory overflow due to recursion.
  • WeakMap and Garbage Collection: WeakMaps that reference themselves can now be garbage collected.
  • DOM Classes Changes: If you rely on PHP’s DOM classes, read the updated list.

Tools and Tips for a Smooth Transition

Don’t fret! PHP’s evolution is a good thing. These changes might require some adjustments, but they’re all for the better.

How to Stay Afloat:

  • Check Out Rector: This open-source tool updates your PHP code base, keeping you ahead of the curve.
  • Stay Informed: Keeping up with PHP updates is like staying ahead in a game. Stay informed to stay ahead!

PHP 8.3 is all about moving forward, and with these tips and insights, you’re well-equipped to embrace these changes. Every update is a step towards a more efficient and powerful PHP.

Happy coding, and here’s to evolving with PHP!

--

--

Infinitypaul
Infinitypaul

Written by Infinitypaul

Software Developer — I admire breaking up complex problems into understandable and sizeable bits, solving daily challenges with technology

No responses yet