Skip to content

Correct xdebug filename/trace function return types in functionMap to include false/null#5788

Merged
ondrejmirtes merged 1 commit into
phpstan:2.2.xfrom
phpstan-bot:create-pull-request/patch-elud85b
May 30, 2026
Merged

Correct xdebug filename/trace function return types in functionMap to include false/null#5788
ondrejmirtes merged 1 commit into
phpstan:2.2.xfrom
phpstan-bot:create-pull-request/patch-elud85b

Conversation

@phpstan-bot
Copy link
Copy Markdown
Collaborator

Summary

PHPStan reported Strict comparison using !== between string and false will always evaluate to true for xdebug_get_profiler_filename() !== false. The xdebug function actually returns false when the profiler is not active, so the comparison is meaningful. The root cause was an inaccurate return type in resources/functionMap.php (string instead of string|false).

Changes

  • resources/functionMap.php:
    • xdebug_get_profiler_filename: stringstring|false (the reported bug).
    • xdebug_get_tracefile_name: stringstring|false (documented as false|string).
    • xdebug_stop_trace: voidstring|false (documented as false|string).
    • xdebug_start_trace: voidstring|null, with parameter signature corrected to ?string $trace_file = null, int $options = 0.
    • Added xdebug_get_gcstats_filename => string|false, xdebug_start_gcstats => string|false, and xdebug_stop_gcstats => string|false (these were missing entirely, which is why xdebug_get_gcstats_filename() !== false was not flagged — it was treated as mixed).
  • tests/PHPStan/Analyser/nsrt/bug-14736.php: new regression test asserting the corrected return types.

Root cause

The functionMap entries for the xdebug filename-returning and trace-control functions only described the success return value and omitted the false/null failure value. xdebug returns false (or null for xdebug_start_trace) when the corresponding subsystem (profiler, tracer, gc-stats collector) is not active. With a return type of plain string, any !== false / === false check was evaluated as always-true/always-false. The fix is the family-wide correction across all the filename getters (get_profiler_filename, get_tracefile_name, get_gcstats_filename) and the trace/gcstats start/stop functions, matching the xdebug documentation.

Test

tests/PHPStan/Analyser/nsrt/bug-14736.php asserts string|false for xdebug_get_profiler_filename, xdebug_get_gcstats_filename, xdebug_get_tracefile_name, xdebug_stop_trace, xdebug_start_gcstats, xdebug_stop_gcstats, and string|null for xdebug_start_trace. The test fails before the fix (e.g. string / mixed / null) and passes after.

Fixes phpstan/phpstan#14736

… include `false`/`null`

- `xdebug_get_profiler_filename` now returns `string|false` (it returns `false` when the profiler is not active), fixing the reported `notIdentical.alwaysTrue` false positive on `xdebug_get_profiler_filename() !== false`.
- Applied the same correction to sibling xdebug functions that return a filename or `false`/`null`:
  - `xdebug_get_tracefile_name` => `string|false`
  - `xdebug_stop_trace` => `string|false`
  - `xdebug_start_trace` => `string|null` (also fixed param signature to `?string $trace_file, int $options`)
- Added missing xdebug gcstats functions with their correct return types:
  - `xdebug_get_gcstats_filename` => `string|false`
  - `xdebug_start_gcstats` => `string|false`
  - `xdebug_stop_gcstats` => `string|false`
- Added regression test tests/PHPStan/Analyser/nsrt/bug-14736.php asserting the corrected return types.
@ondrejmirtes ondrejmirtes merged commit 8670b7b into phpstan:2.2.x May 30, 2026
654 of 661 checks passed
@ondrejmirtes ondrejmirtes deleted the create-pull-request/patch-elud85b branch May 30, 2026 15:30
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.

Function signature: xdebug's xdebug_get_profiler_filename can return false : PHPStan 2.1.56 thinks otherwise

2 participants