{"record":{"id":"065c9e348262a793","repo":"sebastianbergmann/comparator","slug":"failed-asserting-that-two-strings-are-equal","errorCode":null,"errorMessage":"Failed asserting that two strings are equal.","messagePattern":"Failed asserting that two strings are equal\\.","errorType":"exception","errorClass":"ComparisonFailure","httpStatus":null,"severity":"error","filePath":"src/ScalarComparator.php","lineNumber":72,"sourceCode":"        // otherwise 0 == 'Foobar'\n        if ((is_string($expected) && !is_bool($actual)) || (is_string($actual) && !is_bool($expected))) {\n            /** @phpstan-ignore cast.string */\n            $expectedToCompare = @(string) $expectedToCompare;\n\n            /** @phpstan-ignore cast.string */\n            $actualToCompare = @(string) $actualToCompare;\n\n            if ($ignoreCase) {\n                $expectedToCompare = mb_strtolower($expectedToCompare, 'UTF-8');\n                $actualToCompare   = mb_strtolower($actualToCompare, 'UTF-8');\n            }\n        }\n\n        if ($expectedToCompare !== $actualToCompare && is_string($expected) && is_string($actual)) {\n            [$cutExpected, $cutActual] = self::removeOverlongCommonPrefix($expected, $actual);\n            [$cutExpected, $cutActual] = self::removeOverlongCommonSuffix($cutExpected, $cutActual);\n\n            throw new ComparisonFailure(\n                $expected,\n                $actual,\n                $exporter->export($cutExpected),\n                $exporter->export($cutActual),\n                'Failed asserting that two strings are equal.',\n                $this->contextLines(),\n            );\n        }\n\n        /** @phpstan-ignore notEqual.notAllowed */\n        if ($expectedToCompare != $actualToCompare) {\n            throw new ComparisonFailure(\n                $expected,\n                $actual,\n                // no diff is required\n                '',\n                '',\n                sprintf(","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/sebastianbergmann/comparator/blob/00837a9d227b4e123b0b42a91736960f6b0b3583/src/ScalarComparator.php#L54-L90","documentation":"Thrown by ScalarComparator::assertEquals when two scalar values, compared after being cast to strings, are not equal. The guard casts both operands to string (deliberately, to avoid PHP's loose 0 == 'Foobar' comparison) and applies case-folding when ignoreCase is set; the failure fires when the resulting string representations differ. It is a generic comparison failure, so the faulting input is whichever of expected/actual fails strict string comparison.","triggerScenarios":"Thrown at src/ScalarComparator.php:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Print both values with var_export and their types; a match that looks correct may differ in whitespace, encoding, or invisible characters.","Verify types first: a scalar like 0 or false stringifies differently than expected, so compare with strict typing in production code.","Pass ignoreCase=true if the only difference is letter casing.","Normalize encodings/line endings (mb_strtolower, trim, str_replace \"\\r\\n\") before comparison when data comes from external sources.","Fix the producer of the actual value so it yields the expected string."],"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"}