Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 747 Bytes

PossiblyFalseOperand.md

File metadata and controls

39 lines (27 loc) · 747 Bytes

PossiblyFalseOperand

Emitted when using a possibly false value as part of an operation (e.g. +, ., ^ etc).

<?php

function echoCommaPosition(string $str) : void {
    echo 'The comma is located at ' . strpos($str, ','); 
}

How to fix

You can detect the false value with some extra logic:

<?php

function echoCommaPosition(string $str) : void {
    $pos = strpos($str, ',');

    if ($pos === false) {
        echo 'There is no comma in the string';
    }

    echo 'The comma is located at ' . $pos; 
}

Alternatively you can just use a ternary to suppress this issue:

<?php

function echoCommaPosition(string $str) : void {
    echo 'The comma is located at ' . (strpos($str, ',') ?: ''); 
}