Skip to content

Fix syntax error in the headers_with_mbstring.phpt skip condition - #36

Merged
alecpl merged 1 commit into
pear:masterfrom
sebastka:fix/skipif-parse-error
Aug 4, 2026
Merged

alecpl merged 1 commit into
pear:masterfrom
sebastka:fix/skipif-parse-error

Conversation

@sebastka

@sebastka sebastka commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Hello again,

The skip condition in tests/headers_with_mbstring.phpt is a parse error, so the test can never skip. It has stayed invisible because every job in the CI matrix has ext/mbstring, so the branch never executes. The sibling file tests/headers_without_mbstring.phpt already uses the parenthesised form.

--SKIPIF--
<?php
if (!function_exists('mb_substr') || !function_exists('mb_strlen')) {
    die "skip mbstring functions not found!";
}
?>

Why it is a parse error

exit/die accept an argument only in parentheses, so die; and die("x"); are valid while die "x"; is not. That has been true for the whole range this package supports (composer.json requires >=5.2.0), through two different parser implementations.

Checked against PHP 8.5:

$ php -l tests/headers_with_mbstring.phpt   # SKIPIF section extracted
PHP Parse error:  syntax error, unexpected double-quoted string "skip mbstring functions not fo..."

$ for c in 'die "x";' 'exit "x";' 'die("x");' 'exit("x");' 'die;' 'exit;'; do
      printf '<?php %s' "$c" > t.php
      printf '%-14s -> %s\n' "$c" "$(php -l t.php 2>&1 | head -1)"
  done
die "x";       -> PHP Parse error:  syntax error, unexpected double-quoted string "x" in t.php on line 1
exit "x";      -> PHP Parse error:  syntax error, unexpected double-quoted string "x" in t.php on line 1
die("x");      -> No syntax errors detected in t.php
exit("x");     -> No syntax errors detected in t.php
die;           -> No syntax errors detected in t.php
exit;          -> No syntax errors detected in t.php

Sources

Fix

-    die "skip mbstring functions not found!";
+    die("skip mbstring functions not found!");

AI use disclosure

Anthropic's Claude LLM with Opus 5 found the bug and wrote the detailed explanation.

die requires parentheses when given a value, so the skip branch was a parse
error. run-tests treats a --SKIPIF-- that fails to parse as "do not skip",
meaning that on a build without ext/mbstring the test would run against the
non-mbstring encoder and fail with an unrelated diff instead of skipping.

Invisible so far because every job in the CI matrix has ext/mbstring, so the
branch never executed. headers_without_mbstring.phpt already uses the
parenthesised form.
@alecpl
alecpl merged commit 587dced into pear:master Aug 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants