rector icon indicating copy to clipboard operation
rector copied to clipboard

[Downgrade 7.0] Constant array isset

Open jtojnar opened this issue 4 years ago • 5 comments

Feature Request

PHP 5 does not like using isset on ArrayDimFetch on a (class) constant

Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in /in/TJa2A

Diff

const LEVEL_MAP = [ 'foo' => true ];
-var_dump(isset(LEVEL_MAP['foo']));
+var_dump(array_key_exists(LEVEL_MAP, 'foo') && LEVEL_MAP['foo'] !== null);

or maybe

-var_dump(isset(LEVEL_MAP['foo']));
+var_dump((($newTempVariable = LEVEL_MAP) && false) || isset($newTempVariable['foo']));

jtojnar avatar Jan 03 '22 19:01 jtojnar

Hi, thanks for the diff and 3v4l.org. I'm curious, where are you using this downgrade to PHP 7.0?

TomasVotruba avatar Feb 23 '22 14:02 TomasVotruba

Hi, I aim to convert selfoss RSS reader code base to PHP 8.1, while still allowing users to use it on ancient LTS distros (i.e. PHP 5.6).

jtojnar avatar Feb 23 '22 17:02 jtojnar

I see. It's not in our feature list to be honest, as we focus mainly on quality support mainly to PHP 7.1.

Would you like to contribute this rule?

TomasVotruba avatar Feb 23 '22 18:02 TomasVotruba

Yes, it is on my to-do list.

What solution from the opening post do you prefer?

jtojnar avatar Feb 23 '22 18:02 jtojnar

The first one look more straight forward.

TomasVotruba avatar Feb 23 '22 19:02 TomasVotruba

I'm going through old issues to narrow tracker focus on unclear issues that needs our attention. Feel free to send PR with it :+1:

Closing as accepted.

TomasVotruba avatar Aug 17 '22 22:08 TomasVotruba