An if, elseif, else or foreach has an empty statement as its body

tx0/php:stray-semicolon-bodydefaultwarningreliability/control-flowdepth fastbug

What it finds

if ($ready); { start(); }: a semicolon right after the condition is the whole body, so the block after it runs whatever the condition says. Loops with a semicolon body are a known idiom when the work happens in the header, and only foreach, which has no such work, is reported among them.

From the rule's source, stray_semicolon_body.rs.

Example from the rule's tests
<?phpfunction start($ready, $items){    if ($ready);tx0 reports: the body of this if is an empty statement    {        go();    }    foreach ($items as $item);tx0 reports: the body of this foreach is an empty statement    while (step());    for ($i = 0; $i < 3; $i++);    if ($ready) {        go();    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/php:stray-semicolon-body" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/php:stray-semicolon-body] reason="..."

tx0 explain tx0/php:stray-semicolon-body shows the same in the terminal. Found a false positive? Report it.