{"record":{"id":"46c7e80be4b6dc0f","repo":"Intervention/image","slug":"unable-to-remove-color-from-palette-via-array-acce","errorCode":null,"errorMessage":"Unable to remove color from palette via array access","messagePattern":"Unable to remove color from palette via array access","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Colors/Palette.php","lineNumber":82,"sourceCode":"     * @see ArrayAccess::offsetSet()\n     *\n     * @throws NotSupportedException\n     */\n    public function offsetSet(mixed $offset, mixed $value): void\n    {\n        throw new NotSupportedException('Unable to set color via array access, use addColor() instead');\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ArrayAccess::offsetUnset()\n     *\n     * @throws NotSupportedException\n     */\n    public function offsetUnset(mixed $offset): void\n    {\n        throw new NotSupportedException('Unable to remove color from palette via array access');\n    }\n\n    /**\n     * Implementation of IteratorAggregate.\n     *\n     * @return Traversable<ColorInterface>\n     */\n    public function getIterator(): Traversable\n    {\n        return new ArrayIterator($this->toArray());\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see PaletteInterface::addColor()\n     */\n    public function addColor(ColorInterface $color, int $count = 1): self","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Palette.php#L64-L100","documentation":"Palette implements ArrayAccess, but only for reading: offsetGet()/offsetExists() work while offsetSet() and offsetUnset() always throw NotSupportedException. Colors are stored internally in Bin objects keyed by a content hash and carrying occurrence counts, so removing an entry with unset() would bypass that bookkeeping. The library requires you to derive a new palette instead of mutating keys.","triggerScenarios":"unset($palette[0]) or unset($palette['somekey']) on any Intervention\\Image\\Colors\\Palette instance, e.g. one returned by ColorExtractor or $image->extractPalette(...).","commonSituations":"Treating the palette like a plain array because it implements ArrayAccess and is foreach-iterable; porting array-manipulation code that previously ran on plain color arrays; refactoring older Intervention v2 code where extracted colors were stored in normal arrays.","solutions":["Use $palette->filter(callable) to build a new palette that excludes the unwanted colors","Use $palette->slice($offset, $length) to keep or drop a contiguous range of bins","Rebuild manually: new Palette(array_values(array_diff($palette->toArray(), [$color])))","If a generic unset() path cannot be removed, catch Intervention\\Image\\Exceptions\\NotSupportedException and fall back to filter()"],"exampleFix":"// before\nunset($palette[0]); // NotSupportedException: Unable to remove color from palette via array access\n\n// after\n$palette = $palette->slice(1);","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    unset($palette[$index]);\n} catch (\\Intervention\\Image\\Exceptions\\NotSupportedException $e) {\n    $palette = $palette->filter(fn ($color) => !\n        $palette->toArray()[$index]->toHex() === $color->toHex()\n    ); // or rebuild via slice()/toArray()\n}","preventionTips":["Never call unset() on a Palette; ArrayAccess is read-only","Derive new palettes with filter() and slice() instead of mutating","Remember bins carry occurrence counts; removal means rebuilding the palette"],"tags":["palette","arrayaccess","php","intervention-image"],"backgroundTag":"array-access-unsupported","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}