Page MenuHomePhorge

Fix PHP 8.1 exception in Conduit: Make "array_fuse(array $list)" accept null as parameter
ClosedPublic

Authored by aklapper on May 13 2023, 13:28.

Details

Summary

array_fuse in Arcanist is a wrapper for calling array_combine($list, $list).
The latter doesn't accept passing null in PHP 8.2.
Going to /conduit/method/project.create/, entering a name but nothing as members (so we pass null), and calling this method, an exception is thrown.

Thus make array_fuse accept null and return an empty list in such cases.

Closes T15393

Test Plan

Applied this change; afterwards "Method Call Result" page at /api/project.create correctly displayed in the web browser.

Diff Detail

Repository
rARC Arcanist
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

...🤯

Nice shot, really!

If somebody here is wondering why this fixes the issue, and why this works as expected, here a related documentation:

.... One exception to this rule are arguments of the form Type $param = null, where the null default makes the type implicitly nullable. This usage remains allowed, though it is recommended to use an explicit nullable type instead.
https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration

Also this scarying warning deserves a note:

It is also possible to achieve nullable arguments by making null the default value. This is not recommended as if the default value is changed in a child class a type compatibility violation will be raised as the null type will need to be added to the type declaration.
https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.nullable

So, premising we are aware of that concern, here we are vaxinated for that, since this is not a class method but a beautiful function, so the type violation thing is just nowhere a concern.

Probably in 2 years a random folk will propose an RFC to deprecate this null thing aaaand in that case we will just kill that person.

Tested also in very legacy stuff like PHP 5.1 aaaand it works.

Thaaaank🥇

lgtm

This revision is now accepted and ready to land.May 20 2023, 21:56