{"record":{"id":"97dea32d0717baa0","repo":"symfony/symfony","slug":"memcachedadapter-serializer-option-must-be-php","errorCode":null,"errorMessage":"MemcachedAdapter: \"serializer\" option must be \"php\" or \"igbinary\".","messagePattern":"MemcachedAdapter: \"serializer\" option must be \"php\" or \"igbinary\"\\.","errorType":"exception","errorClass":"Symfony\\Component\\Cache\\Exception\\CacheException","httpStatus":null,"severity":"error","filePath":"src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php","lineNumber":59,"sourceCode":"     * Using a RedisAdapter is recommended instead. If you cannot do otherwise, be aware that:\n     * - the Memcached::OPT_BINARY_PROTOCOL must be enabled\n     *   (that's the default when using MemcachedAdapter::createConnection());\n     * - tags eviction by Memcached's LRU algorithm will break by-tags invalidation;\n     *   your Memcached memory should be large enough to never trigger LRU.\n     *\n     * Using a MemcachedAdapter as a pure items store is fine.\n     */\n    public function __construct(\\Memcached $client, string $namespace = '', int $defaultLifetime = 0, ?MarshallerInterface $marshaller = null)\n    {\n        if (!static::isSupported()) {\n            throw new CacheException('Memcached > 3.1.5 is required.');\n        }\n        $this->maxIdLength = self::MAX_KEY_LENGTH;\n\n        if ('Memcached' === $client::class) {\n            $opt = $client->getOption(\\Memcached::OPT_SERIALIZER);\n            if (\\Memcached::SERIALIZER_PHP !== $opt && \\Memcached::SERIALIZER_IGBINARY !== $opt) {\n                throw new CacheException('MemcachedAdapter: \"serializer\" option must be \"php\" or \"igbinary\".');\n            }\n            $this->maxIdLength -= \\strlen($client->getOption(\\Memcached::OPT_PREFIX_KEY));\n            $this->client = $client;\n        } else {\n            $this->lazyClient = $client;\n        }\n\n        parent::__construct($namespace, $defaultLifetime);\n        $this->enableVersioning();\n        $this->marshaller = $marshaller ?? new DefaultMarshaller();\n    }\n\n    public static function isSupported(): bool\n    {\n        return \\extension_loaded('memcached') && version_compare(phpversion('memcached'), '3.1.6', '>=');\n    }\n\n    /**","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/symfony/symfony/blob/698e28026c22cf35d032cdb6e800db48b1535790/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php#L41-L77","documentation":"Thrown by MemcachedAdapter's constructor (MemcachedAdapter.php:58) when the provided \\Memcached client's OPT_SERIALIZER is set to something other than SERIALIZER_PHP or SERIALIZER_IGBINARY. The adapter marshals values itself via DefaultMarshaller, so a conflicting client serializer (e.g. JSON) would double-encode and corrupt data.","triggerScenarios":"Constructing `new MemcachedAdapter($client)` where $client->setOption(\\Memcached::OPT_SERIALIZER, \\Memcached::SERIALIZER_JSON) was called beforehand. Passing a client created by hand instead of via MemcachedAdapter::createConnection().","commonSituations":"Sharing a Memcached instance between this adapter and legacy code that set SERIALIZER_JSON. A pre-configured client injected via DI that defaults to JSON serialization. Migrating from a custom memcached wrapper that used JSON.","solutions":["Reset the serializer before passing the client: $client->setOption(\\Memcached::OPT_SERIALIZER, \\Memcached::SERIALIZER_PHP);","Prefer creating the client via MemcachedAdapter::createConnection() which sets a sane default serializer.","If you need JSON serialization, do it in your values before caching, not via the memcached serializer."],"exampleFix":"// before\n$client = new \\Memcached();\n$client->setOption(\\Memcached::OPT_SERIALIZER, \\Memcached::SERIALIZER_JSON);\nnew MemcachedAdapter($client);\n\n// after\n$client->setOption(\\Memcached::OPT_SERIALIZER, \\Memcached::SERIALIZER_PHP);\nnew MemcachedAdapter($client);","handlingStrategy":"validation","validationCode":"$opt = $client->getOption(\\Memcached::OPT_SERIALIZER);\nif (!in_array($opt, [\\Memcached::SERIALIZER_PHP, \\Memcached::SERIALIZER_IGBINARY], true)) {\n    $client->setOption(\\Memcached::OPT_SERIALIZER, \\Memcached::SERIALIZER_PHP);\n}\nnew MemcachedAdapter($client);","typeGuard":"function hasCompatibleSerializer(\\Memcached $c): bool\n{\n    return in_array($c->getOption(\\Memcached::OPT_SERIALIZER), [\\Memcached::SERIALIZER_PHP, \\Memcached::SERIALIZER_IGBINARY], true);\n}","tryCatchPattern":null,"preventionTips":["Build the client via MemcachedAdapter::createConnection() to inherit sane defaults.","Don't share a Memcached instance with code that sets SERIALIZER_JSON.","Document that this adapter marshals values itself; client serializer must be raw-ish."],"tags":["cache","memcached","configuration","serializer"],"analyzedSha":"698e28026c22cf35d032cdb6e800db48b1535790","analyzedAt":"2026-08-06T23:40:49.025Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}