Fixed php 8.4+ compatibility

Xon

Well-known member
Affected version
2.3
This hasn't passed yet, but the discussion doesn't look like it'll have any roadblocks.

This will break things function definitions like:
PHP:
function foo(User $user = null)
Thankfully the fix isn't too bad, but will be a backwards compatibility breaking change so hopefully this can get into 2.3

I've been trying to craft a regex to find these (function.*\([^\?\)]*\s*[\w]+\s*\$[\w]+\s*=\s*null\s*\) is the closest I've got), but it is somewhat false positive and error prone
 

This doesn't error:
PHP:
class a {function c(int $a = null) {} }
class b extends a {function c(?int $a = null) {} }
class d extends b {function c(int $a = null) {} }

For add-ons developers, we can just update to add ? to the type signature even if XF hasn't and it'll work :D
 
1) it's an open bug report so clearly not been addressed yet
2) the sheer majority of the code in 2.3 was written way before 8.4 was a thing

All in good time, people.
 
On the upside, from that 3v4L snippet this is backwards compatibility breaking change but not a forwards compatibility breaking change like most php changes.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.0 RC 3).

Change log:
Use nullable parameter type declarations for PHP 8.4 compatibility
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom