replace php constant index to named index #8279
|
In php 4, and php 5 a constant if not found is automatically converted to string so a code like this is ok:
is equivalent to
How to use rector to convert these types of indexes to work correctly in php 7 / 8? Thanks! |
Answered by
samsonasik
Oct 26, 2023
Replies: 1 comment
|
I think you can create custom rule for that, as creating rule for core is too risky for core:
if ($this->reflectionProvider->hasConstant(new Name($constantName), $scope)) {If not, change to string, you can check rector's rector/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php Lines 78 to 80 in ae4c0b7 and create custom rule based on your needs. |
0 replies
Answer selected by
samsonasik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you can create custom rule for that, as creating rule for core is too risky for core:
$rectorConfig->bootstrapFiles(), ensure that it actually not a constantIf not, change to string, you can check rector's
SensitiveConstantNameRectorwhich change to case sensitive constant name instead:rector/rules/Php73/Rector/ConstFetch/SensitiveConstantNameRector.php
Lines 78 to 80 in ae4c0b7