website/errors/ternary.resultUnused.md
<?php declare(strict_types = 1);
function doFoo(bool $a, string $b, string $s): void
{
$a ? $b : $s;
}
A ternary expression is used as a standalone statement, but its result is not assigned to a variable, returned, or passed as an argument. The expression evaluates to a value that is immediately discarded, which means it has no effect on the program.
This usually indicates one of the following:
if/else statement for side effects instead.Assign the result to a variable or return it:
-$a ? $b : $s;
+$result = $a ? $b : $s;
Or use an if/else statement if the branches have side effects:
-$a ? doSomething() : doSomethingElse();
+if ($a) {
+ doSomething();
+} else {
+ doSomethingElse();
+}