{"record":{"id":"a47140322d12e423","repo":"Intervention/image","slug":"value-for-argument-setnative-native-must-be-i-a47140","errorCode":null,"errorMessage":"Value for argument setNative() \"$native\" must be instanceof of Imagick","messagePattern":"Value for argument setNative\\(\\) \"\\$native\" must be instanceof of Imagick","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Frame.php","lineNumber":60,"sourceCode":"     *\n     * @see DriverInterface::toImage()\n     */\n    public function toImage(DriverInterface $driver): ImageInterface\n    {\n        return new Image($driver, new Core($this->native()));\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DriverInterface::setNative()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function setNative(mixed $native): FrameInterface\n    {\n        if (!$native instanceof Imagick) {\n            throw new InvalidArgumentException(\n                'Value for argument setNative() \"$native\" must be instanceof of ' . Imagick::class,\n            );\n        }\n\n        $this->native = $native;\n\n        return $this;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DriverInterface::native()\n     */\n    public function native(): Imagick\n    {\n        return $this->native;\n    }","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Frame.php#L42-L78","documentation":"Frame::setNative(mixed $native) enforces that only an Imagick instance can back an Imagick Frame (src/Drivers/Imagick/Frame.php:59-63); anything else — a GdImage, array, null, mock — throws InvalidArgumentException naming the expected class. It is a hard type barrier at the driver boundary: the Imagick driver cannot operate on another driver's core object.","triggerScenarios":"Calling $frame->setNative() with the wrong core, e.g. a GD resource from the GD driver, null after a failed decode, or a fabricated value in tests; typically code that mixes ImageManager instances configured with different drivers.","commonSituations":"Apps instantiating both GD and Imagick managers and swapping cores between them; migrating v2 code where ->getCore() returned varying types; test fixtures constructing frames by hand.","solutions":["Pass an Imagick instance: new Imagick() or the value from $image->core()->native() of an Imagick-driver image","Standardize one driver per pipeline: create the manager with ImageManager::withDriver(Driver::Imagick)","Type-hint or assert the variable against Imagick before calling setNative()"],"exampleFix":"// before\n$frame->setNative($gdImage); // GdImage from the GD driver\n\n// after\nif (!$native instanceof Imagick) {\n    throw new InvalidArgumentException(\n        'Expected Imagick instance, got ' . get_debug_type($native)\n    );\n}\n$frame->setNative($native);","handlingStrategy":"type-guard","validationCode":"if (!$native instanceof Imagick) {\n    throw new InvalidArgumentException(\n        'Expected Imagick instance, got ' . get_debug_type($native)\n    );\n}\n$frame->setNative($native);","typeGuard":"function isImagickNative(mixed $native): bool\n{\n    return $native instanceof Imagick;\n}\n\n// usage\nif (isImagickNative($native)) {\n    $frame->setNative($native);\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $frame->setNative($candidate);\n} catch (InvalidArgumentException $e) {\n    // wrong core type; re-create from the correct driver instead of coercing\n    throw new LogicException('Driver mismatch: rebuild the core with Driver::Imagick', 0, $e);\n}","preventionTips":["Create one ImageManager per driver and never pass cores between them","Source natives only via $image->core()->native() from the same driver","Type-hint parameters as Imagick in custom modifiers so the mismatch fails at the boundary"],"tags":["imagick","type-error","invalid-argument","driver-mismatch","frame"],"backgroundTag":"wrong-driver-native-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}