{"record":{"id":"f599273dd2f538c1","repo":"sebastianbergmann/comparator","slug":"s-does-not-match-expected-type-s","errorCode":null,"errorMessage":"%s does not match expected type \"%s\".","messagePattern":"(.+?) does not match expected type \"(.+?)\"\\.","errorType":"exception","errorClass":"ComparisonFailure","httpStatus":null,"severity":"error","filePath":"src/TypeComparator.php","lineNumber":35,"sourceCode":" * @no-named-arguments Parameter names are not covered by the backward compatibility promise for sebastian/comparator\n *\n * @internal This class is not covered by the backward compatibility promise for sebastian/comparator\n */\nfinal class TypeComparator extends Comparator\n{\n    public function accepts(mixed $expected, mixed $actual): bool\n    {\n        return true;\n    }\n\n    /**\n     * @throws ComparisonFailure\n     * @throws ObjectNotSupportedException\n     */\n    public function assertEquals(mixed $expected, mixed $actual, float $delta = 0.0, bool $canonicalize = false, bool $ignoreCase = false): void\n    {\n        if (gettype($expected) !== gettype($actual)) {\n            throw new ComparisonFailure(\n                $expected,\n                $actual,\n                // we don't need a diff\n                '',\n                '',\n                sprintf(\n                    '%s does not match expected type \"%s\".',\n                    $this->exporter()->shortenedExport($actual),\n                    gettype($expected),\n                ),\n                $this->contextLines(),\n            );\n        }\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":51,"githubUrl":"https://github.com/sebastianbergmann/comparator/blob/00837a9d227b4e123b0b42a91736960f6b0b3583/src/TypeComparator.php#L17-L51","documentation":"Thrown by TypeComparator::assertEquals, the fallback comparator whose accepts() returns true for any pair of values. It fires whenever the expected and actual values have different PHP types (e.g. expected int but actual string) — it is a generic type-mismatch guard, and the faulting input is the actual value whose gettype() differs from the expected value's.","triggerScenarios":"Thrown at src/TypeComparator.php:35 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check gettype()/get_debug_type() on both values; the mismatch is a type difference, not a value difference.","Cast or convert the actual value to the expected type only when the type coercion is intentional and safe.","Tighten input sources (strict_types=1, parameter type declarations) so values arrive with the correct type.","Fix the producing code path (e.g. a function returning null or string instead of int) rather than loosening the assertion.","Ensure a more specific comparator accepts the pair first if a structural comparison was intended instead of a type check."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"00837a9d227b4e123b0b42a91736960f6b0b3583","analyzedAt":"2026-09-15T03:36:55.154Z","contentChangedAt":"2026-09-15T03:36:55.154Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}