PHP 8.0 and 8.1 come with lots of new stuff. There are some major features that will be useful in new code, such as union and intersection type annotations, named arguments, attributes, enums, or readonly properties.
But there are also many smaller, straightforward syntax improvements that could be used to improve our existing code, in MediaWiki as well as extensions:
- T396815 - Non-capturing catch ( Exception )
- Trailing commas in (multi-line) function parameter lists
- htmlspecialchars() and htmlentities() default flags escape single-quotes
- str_contains(), str_starts_with() and str_ends_with() functions
- Nullsafe operator $foo?->bar()?->baz
- First-class callable syntax $callable = $foo->bar( ... );
- Constructor property promotion
- Match expression match
I'd like us to have a good look at them, and figure out:
- Which of them we could require to be used with PHPCS, Phan or other tools, and introduce semi-automatically with regexp replacements and careful review?
- Which of them we could introduce entirely automatically with PHPCBF or other tools?
We should also review the code conventions on MediaWiki.org and see if anything should be updated to recommend these.
We can use these features today (following T328921 and T319432), but we may want to wait with large-scale changes until support for MediaWiki 1.39 is dropped in November, to avoid inconvenience when backporting patches.