{"record":{"id":"2a69ee817f4ef400","repo":"Intervention/image","slug":"image-source-must-be-of-type-splfileinfo","errorCode":null,"errorMessage":"Image source must be of type SplFileInfo","messagePattern":"Image source must be of type SplFileInfo","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php","lineNumber":50,"sourceCode":"    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DecoderInterface::decode()\n     *\n     * @throws InvalidArgumentException\n     * @throws ImageDecoderException\n     * @throws DriverException\n     * @throws StateException\n     * @throws DirectoryNotFoundException\n     * @throws FileNotFoundException\n     * @throws FileNotReadableException\n     */\n    public function decode(mixed $input): ImageInterface\n    {\n        if (!$input instanceof SplFileInfo) {\n            throw new InvalidArgumentException('Image source must be of type ' . SplFileInfo::class);\n        }\n\n        try {\n            return parent::decode(self::filePathFromSplFileInfoOrFail($input));\n        } catch (DecoderException) {\n            throw new ImageDecoderException(SplFileInfo::class . ' contains unsupported image type');\n        }\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":60,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Decoders/SplFileInfoImageDecoder.php#L32-L60","documentation":"SplFileInfoImageDecoder only accepts SplFileInfo objects; decode() throws InvalidArgumentException immediately for any other value. Through ImageManager this decoder is auto-selected only for SplFileInfo input, so hitting it usually means invoking the decoder manually or forcing it via the decoders argument of decode().","triggerScenarios":"$manager->decode($path, SplFileInfoImageDecoder::class) with a plain string, or (new SplFileInfoImageDecoder($driver))->decode('image.png') called directly.","commonSituations":"Porting code that mixes path strings with SplFileInfo, passing a string to a helper documented to build SplFileInfo, forcing a specific decoder as the second decode() argument.","solutions":["Pass an SplFileInfo instance: new SplFileInfo($path)","Or pass the plain path and let the automatic decoder chain select FilePathImageDecoder","Use $manager->decodeSplFileInfo($splFileInfo) for explicit, typed entry"],"exampleFix":"// before\n$image = $manager->decode($path, SplFileInfoImageDecoder::class); // InvalidArgumentException\n\n// after\n$image = $manager->decode(new SplFileInfo($path), SplFileInfoImageDecoder::class);\n// or simply: $image = $manager->read($path);","handlingStrategy":"type-guard","validationCode":"if (!$input instanceof SplFileInfo) {\n    $input = new SplFileInfo((string) $input);\n}\n$image = $manager->decodeSplFileInfo($input);","typeGuard":"function isSplFileInfo(mixed $value): bool\n{\n    return $value instanceof SplFileInfo;\n}","tryCatchPattern":"try {\n    $image = $decoder->decode($input);\n} catch (InvalidArgumentException $e) {\n    // input was not an SplFileInfo; wrap it and retry\n}","preventionTips":["Prefer $manager->read($anySource) and let the chain pick the decoder","Type helper parameters as SplFileInfo so the compiler catches misuse","Avoid forcing specific decoders unless necessary"],"tags":["splfileinfo","type-check","decoder","gd"],"backgroundTag":"invalid-argument-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}