Phpinspectionsea: "Use substring search instead" suggested for simple string character check

Created on 29 May 2020  路  4Comments  路  Source: kalessil/phpinspectionsea

| Subject | Details |
| :------------- | :---------------------------------------------------------------------------- |
| Plugin | Php Inspections (EA Extended) 4.0.4.1 |
| Language level | 7.4|

Current behaviour

<?php
        if (is_string($foo) && $foo[0] === '{') {
        }

image

Expected behaviour

I would not expect any suggestion to change this here at all 馃

Environment details

PhpStorm 2020.1.2 RC
Build #PS-201.7846.64, built on May 27, 2020
Runtime version: 11.0.7+10-b765.53 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.4
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Registry: run.processes.with.pty=TRUE, undo.documentUndoLimit=1000, debugger.watches.in.variables=false, vcs.commit.tool.window=false, ide.tooltip.initialDelay=255, update.run.configuration.actions.from.cache=true
Non-Bundled Plugins: IdeaVIM, PlantUML integration, com.intellij.ideolog, com.ultrahob.zerolength.plugin, net.vektah.codeglance, org.jetbrains.idea.project.template.variables, org.jetbrains.plugins.node-remote-interpreter, ru.adelf.idea.dotenv, NEON support, de.espend.idea.laravel, com.kalessil.phpStorm.phpInspectionsEA, de.espend.idea.php.annotation, com.intellij.lang.puppet, org.sylfra.idea.plugins.linessorter

enhancement

Most helpful comment

Yep, looks pretty confusing. @mfn, @vpArth, @funivan, @rentalhost let's decide if we want to drop this pattern (the idea was to prevent 'Notice: Uninitialized string offset: 0') or introduce new setting, or perhaps something else.

My personal preference would be to drop the pattern completely ($string[0] === '?').

All 4 comments

Documentation for that inspection links to 'substr(...)' could be replaced with 'strpos(...)' rule.

But there is not any substr call in $str[0]

Yep, looks pretty confusing. @mfn, @vpArth, @funivan, @rentalhost let's decide if we want to drop this pattern (the idea was to prevent 'Notice: Uninitialized string offset: 0') or introduce new setting, or perhaps something else.

My personal preference would be to drop the pattern completely ($string[0] === '?').

No objections dropping it

Dropped!

Was this page helpful?
0 / 5 - 0 ratings