1.2.1095. Short Ternary

Short ternaries are the ternary operator, where the middle operand was left out.

Written that way, the operator checks if the first operand is empty() : in that case, the second operand is used; Otherwise, the first operand is used.

<?php
     // $b is now 2
     $b = $a ?: 2;
     // $c is now 2 also
     $c = $b ?: 4;
?>

See also Ternary Operator.

1.2.1095.1. Specs

Short name

Php/ShortTernary

Rulesets

All, Appinfo, Changed Behavior, One Liners

Exakat since

2.5.2

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

short-ternary

Available in

Entreprise Edition, Exakat Cloud