View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0002419 | Xdebug | Code Coverage | public | 2026-04-24 07:17 | 2026-04-24 09:36 |
| Reporter | sebastian | Assigned To | derick | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | resolved | Resolution | not fixable | ||
| Product Version | 3.5.1 | ||||
| Summary | 0002419: Line coverage does not report ternary branch lines when ternary is inside an array literal | ||||
| Description | When a multiline ternary operator is used as a value inside an array literal, xdebug_get_code_coverage() does not report coverage data for the lines containing the true and false branch expressions. The same ternary in a simple variable assignment context reports both branch lines correctly. This affects php-code-coverage (used by PHPUnit). When a ternary operator spans multiple lines inside an array literal, the branch expression lines do not appear in coverage reports at all. They are neither green (executed) nor red (not executed). They are simply not treated as executable lines. Reported in https://github.com/sebastianbergmann/php-code-coverage/issues/1029 | ||||
| Steps To Reproduce | Scriptsternary_assignment.php:
ternary_in_array.php:
Outputternary_assignment.php (simple variable assignment):
Both branch lines (7 and 8) are reported. Their status correctly reflects which branch was taken. ternary_in_array.php (ternary as value in array literal):
Lines 8 (? ['yes']) and 9 (: ['no']) are absent from the coverage data in both calls. There is no way to determine from the reported data whether either branch was taken. AnalysisThe opcodes generated for bar() in both scripts are structurally identical (shown via opcache.opt_debug_level=0x20000):
Both have the same QM_ASSIGN opcodes for the true and false branch values. The difference in coverage output suggests that the opcode-to-line mapping for the QM_ASSIGN opcodes differs between the two contexts: in the simple assignment case each QM_ASSIGN is mapped to its source line (7 and 8); in the array literal case both appear to be mapped to the condition line (7), making lines 8 and 9 invisible to line coverage. | ||||
| Tags | No tags attached. | ||||
| Operating System | |||||
| PHP Version | 8.5.0-8.5.4 | ||||