{"record":{"id":"bc55688628116550","repo":"Intervention/image","slug":"value-for-disposal-method-method-must-be-0-1","errorCode":null,"errorMessage":"Value for disposal method \"$method\" must be 0, 1, 2 or 3","messagePattern":"Value for disposal method \"\\$method\" must be 0, 1, 2 or 3","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Frame.php","lineNumber":127,"sourceCode":"     *\n     * @see FrameInterface::disposalMethod()\n     */\n    public function disposalMethod(): int\n    {\n        return $this->disposalMethod;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see FrameInterface::setDisposalMethod()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function setDisposalMethod(int $method): FrameInterface\n    {\n        if (!in_array($method, [0, 1, 2, 3])) {\n            throw new InvalidArgumentException('Value for disposal method \"$method\" must be 0, 1, 2 or 3');\n        }\n\n        $this->disposalMethod = $method;\n\n        return $this;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see FrameInterface::setOffset()\n     */\n    public function setOffset(int $left, int $top): FrameInterface\n    {\n        $this->offsetLeft = $left;\n        $this->offsetTop = $top;\n\n        return $this;","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Frame.php#L109-L145","documentation":"GIF disposal methods are defined by the GIF89a specification as 0-3 (unspecified/none, do not dispose, restore to background, restore to previous). setDisposalMethod() enforces exactly that set; any other integer throws InvalidArgumentException.","triggerScenarios":"$frame->setDisposalMethod(4) or values copied from external GIF tooling/parsers that emit out-of-range codes; uninitialized variables defaulting to -1 fed into the setter.","commonSituations":"Interoperating with custom GIF utilities that number disposal differently or emit experimental codes, copying raw metadata between libraries without mapping.","solutions":["Map or clamp external values into 0-3 before setting","Use literals or named constants documented by the GIF89a spec","Validate with in_array($method, [0, 1, 2, 3], true) before the call"],"exampleFix":"// before\n$frame->setDisposalMethod($externalValue); // may be 4 or more\n\n// after\n$method = in_array($externalValue, [0, 1, 2, 3], true) ? $externalValue : 0;\n$frame->setDisposalMethod($method);","handlingStrategy":"validation","validationCode":"$method = in_array($externalValue, [0, 1, 2, 3], true) ? $externalValue : 0;\n$frame->setDisposalMethod($method);","typeGuard":"function isValidDisposalMethod(int $method): bool\n{\n    return in_array($method, [0, 1, 2, 3], true);\n}","tryCatchPattern":"try {\n    $frame->setDisposalMethod($value);\n} catch (InvalidArgumentException $e) {\n    $frame->setDisposalMethod(0); // clamp to 'unspecified'\n}","preventionTips":["Map disposal codes from external tools into 0-3 explicitly","Initialize disposal variables to 0, never -1","Read the GIF89a disposal semantics before copying values"],"tags":["gif","disposal-method","validation","frame"],"backgroundTag":"value-out-of-range","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}