Skip to content

Commit eb9ff9b

Browse files
committed
bug #49395 fix trying to load Memcached before checking we can (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- fix trying to load Memcached before checking we can | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When the extension is not installed, using `Memcached::*` in const breaks before `isSupported()` could be called. Commits ------- 818fdcb [Cache] fix trying to load Memcached before checking we can
2 parents 7f3e387 + 818fdcb commit eb9ff9b

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ class MemcachedAdapter extends AbstractAdapter
3232

3333
protected $maxIdLength = 250;
3434

35-
private const DEFAULT_CLIENT_OPTIONS = [
36-
'persistent_id' => null,
37-
'username' => null,
38-
'password' => null,
39-
\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_PHP,
40-
];
41-
4235
private $marshaller;
4336
private $client;
4437
private $lazyClient;
@@ -106,10 +99,9 @@ public static function createConnection($servers, array $options = [])
10699
}
107100
set_error_handler(function ($type, $msg, $file, $line) { throw new \ErrorException($msg, 0, $type, $file, $line); });
108101
try {
109-
$options += static::DEFAULT_CLIENT_OPTIONS;
110-
$client = new \Memcached($options['persistent_id']);
111-
$username = $options['username'];
112-
$password = $options['password'];
102+
$client = new \Memcached($options['persistent_id'] ?? null);
103+
$username = $options['username'] ?? null;
104+
$password = $options['password'] ?? null;
113105

114106
// parse any DSN in $servers
115107
foreach ($servers as $i => $dsn) {
@@ -199,7 +191,7 @@ public static function createConnection($servers, array $options = [])
199191
$options[\constant('Memcached::OPT_'.$name)] = $value;
200192
}
201193
}
202-
$client->setOptions($options);
194+
$client->setOptions($options + [\Memcached::OPT_SERIALIZER => \Memcached::SERIALIZER_PHP]);
203195

204196
// set client's servers, taking care of persistent connections
205197
if (!$client->isPristine()) {

0 commit comments

Comments
 (0)