Skip to content

False type_mismatch_argument for strtr() with replace-pairs array #165

@alexchexes

Description

@alexchexes

PHPantom version

phpantom_lsp 0.8.0-dirty

Installation method

Pre-built binary from GitHub Releases

Operating system

Windows x86_64

Editor

VS Code

Bug description

PHPantom reports a type mismatch for the valid two-argument strtr() form where the second argument is the replacement-pairs array.

Expected: no diagnostic.
Actual: Argument 2 ($from) expects string, got array{...} with code type_mismatch_argument.

Steps to reproduce

  1. Use any supported PHP version.
  2. Create a PHP file with:
<?php

$result = strtr('Hello :name', [
    ':name' => 'Alex',
]);
  1. Open the file with PHPantom enabled.
  2. Check diagnostics on the second argument.

Error output or panic trace


.phpantom.toml

No version-specific settings are required.

Additional context

strtr() has two valid signatures:

strtr(string $string, string $from, string $to): string
strtr(string $string, array $replace_pairs): string

PHPantom appears to validate the call against the three-argument string signature only.

Binary source

Originally observed in the VS Code extension v0.5.0. Reproduced with the extension-cached GitHub Releases binary

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions