Page MenuHomePhorge

"Modernize" codebase to features available since PHP 5.5 (that is the actual announced minimum)
Open, WishlistPublic

Description

Phorge officially supports PHP >= 5.5.

The minimum version 5.5 is reasonable and not under re-discussion. What is probably not reasonable anymore, is to continue to maintain very legacy and obsolete PHP features from PHP 5.4, or PHP 5.3, etc.

This Task is about refactoring on (all criteria respected):

  1. migrating very-legacy PHP approaches that can be easily replaced by "modern" approaches since PHP 5.5
  2. keep old-fashioned approaches that are still recommended from the Phorge style manual

Riepilogue

Thank you for your help in contributing to this table:

From (old code)To (proposed code)SinceInternal conversion rule name in rector.phpShould we apply this replacement?Patch
dirname(__FILE__)__DIR__5.3DirNameFileConstantToDirConstantRector๐Ÿ‘ Why not! the __DIR__ is shorter and more readable.D25073
$foo ? $foo : $default$foo ?: $default5.3TernaryToElvisRector๐Ÿ‘ Why not! it prevents copy-paste mistakes with long vars
count(phutil_utf8v($v))phutil_utf8_strlen($v)5.0none๐Ÿ‘ Why not! the count(phutil_utf8v()) is damn slow and inefficient compared to phutil_utf8_strlen() that can use the native mb_strlen() (since PHP 4) that is probably blazing faster.
__CLASS__self::class??ClassConstantToSelfClassRectorโŒ› NO: I don't know why Rector proposes this. I am confused https://stackoverflow.com/q/75648554/3451846
array( 1, 2 )[ 1, 2 ]5.4LongArrayToShortArrayRectorโŒ› NOT NOW: Phorge recommends this in the style manual atm
id( new A() )->b()( new A() )->b()5.4none๐Ÿ‘ The id( $v ) that returns $v was a smart trick and was useful in 5.3 but since 5.4 it just creates confusion. We should reduce its usage.
id( $a->b() )->c()$a->b()->c() 5.0none๐Ÿ‘ Why not! Adding parentheses just add complexity.
( $a->b() )->c()$a->b()->c() 5.0none๐Ÿ‘ Why not! Adding parentheses add complexity and it's only supported in PHP 7.0.
id( clone $a )->b()( new A() )->b()7.0noneโŒ› NOT NOW: this was introduced since PHP 7.0 so it's still needed
(method returning nothing without PHPDoc )add /**@return never*/everReturnNeverTypeRectorโŒ› NOT NOW: This can be confusing. Since this can change documentation on base empty method, and not actual full method.

Here the reference for the Rector.php rules:

https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md

NOTE: If you have ANY feedback, leave a comment or add a column etc. This riepilogue is probably partial but a reasonable starting point.
NOTE: These features are propose because Rector.php seems very good at making these small block substitutions. So it's just up to our choice whenever to apply them or not.

Event Timeline