Page MenuHomePhabricator

Use PHP 8.1 features in the ActionAPI folder
Open, Stalled, MediumPublic2 Estimated Story Points

Description

Following updates can be performed:

  • never return type
  • Array unpacking with string keys
  • Named Arguments where necessary
  • Union Types
  • Nullsafe Operator

Event Timeline

abi_ triaged this task as Medium priority.Aug 28 2025, 4:40 PM
abi_ moved this task from Needs Triage to Maintenance on the ContentTranslation board.
abi_ set the point value for this task to 2.
abi_ moved this task from Backlog to In Progress on the LPL Essential (2025 Jul-Oct) board.

Change #1182888 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/ContentTranslation@master] ApiContentTranslationSave: Update to use PHP 8.1 features

https://gerrit.wikimedia.org/r/1182888

Change #1182891 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/ContentTranslation@master] ApiContentTranslationDelete: Update to use PHP 8.1 features

https://gerrit.wikimedia.org/r/1182891

Nikerabbit subscribed.

We have noticed a blocker that Phan doesn't seem to support all these features yet. More details to be added.

abi_ changed the task status from Open to Stalled.Sep 4 2025, 12:34 PM
abi_ removed abi_ as the assignee of this task.

We're currently unable to use nullsafe operator due to limitations with phan. Possibly also the never return type. I think we can put this task in backlog and revisit once we have better support for PHP 8.1 feature detection in phan. Similar ticket: T334726

Upstream has fixed the Phan limitation this task is blocked on.

phan/phan#5571 (commit 7b493cda) was merged on 2026-09-15, closing phan/phan#5569. It teaches Phan's condition visitors to narrow a nullsafe receiver to non-null inside a guarded branch: $x?->m() evaluates to null when $x is null, so a truthy test on it proves $x is not null. ConditionVisitor had no case for ast\AST_NULLSAFE_METHOD_CALL, which is why $block stayed ?Block.

That is precisely the error reported on change 1182891:

includes/ActionApi/ApiContentTranslationDelete.php:33 PhanTypeMismatchArgumentNullable
Argument 1 ($block) is $block of type ?\MediaWiki\Block\AbstractBlock|... but
ApiContentTranslationDelete::dieBlocked() takes \MediaWiki\Block\Block

As @Nikerabbit suspected above, the operator itself was already supported; the gap was in condition narrowing, not parsing.

This does not unblock CI yet. mediawiki/mediawiki-phan-config pins an exact version:

"phan/phan": "6.0.7"

and 6.0.7 (released 2026-06-22) predates the fix, which currently exists only on Phan's master branch. Checking a reduced version of the same pattern against both:

PhanResult
6.0.74 x PhanTypeMismatchArgumentNullable
master 7b493cdclean

So rechecking 1182891 today would still fail. Three things need to happen, in order:

  1. Phan cuts a release containing 7b493cda
  2. mediawiki/tools/phan bumps its phan/phan pin to that release (a one-line change)
  3. 1182891 is rechecked

All four nullsafe shapes are covered by the upstream fix, not just the method-call form: property fetch, strict comparison against true, and the inverted if ( !$x?->m() ) { return; } early-return guard all narrow correctly now. So the wider "use PHP 8.1 features" work in this task should not hit the same wall again once the pin moves.

Note also that change 1182888 has been Verified+2 since 2026-03-12, so 1182891 is the only one of the pair still held up.

Change #1182888 merged by jenkins-bot:

[mediawiki/extensions/ContentTranslation@master] ApiContentTranslationSave: Update to use PHP 8.1 features

https://gerrit.wikimedia.org/r/1182888