Skip to content

Commit d9d5ce8

Browse files
committed
Fixed a bug with config options and test for it
1 parent 6def3bb commit d9d5ce8

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

php_memcached.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ static int php_memc_set_option(php_memc_t *i_obj, long option, zval *value TSRML
25402540
flag = (memcached_behavior) option;
25412541
convert_to_long(value);
25422542

2543-
if (Z_LVAL_P(value) >= 0 && Z_LVAL_P(value) < MEMCACHED_BEHAVIOR_MAX) {
2543+
if (flag >= 0 && flag < MEMCACHED_BEHAVIOR_MAX) {
25442544
rc = memcached_behavior_set(m_obj->memc, flag, (uint64_t) Z_LVAL_P(value));
25452545
}
25462546
else {

tests/setoptions.phpt

+6-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Set options using setOptions
33
--SKIPIF--
44
<?php if (!extension_loaded("memcached")) print "skip"; ?>
55
--FILE--
6-
<?php
6+
<?php
77
$m = new Memcached();
88

99
/* existing options */
@@ -12,6 +12,7 @@ var_dump($m->setOptions(array(
1212
Memcached::OPT_SERIALIZER => Memcached::SERIALIZER_PHP,
1313
Memcached::OPT_COMPRESSION => 0,
1414
Memcached::OPT_LIBKETAMA_COMPATIBLE => 1,
15+
Memcached::OPT_CONNECT_TIMEOUT => 5000,
1516
)));
1617

1718
var_dump($m->getOption(Memcached::OPT_PREFIX_KEY) == 'a_prefix');
@@ -20,18 +21,14 @@ var_dump($m->getOption(Memcached::OPT_COMPRESSION) == 0);
2021
var_dump($m->getOption(Memcached::OPT_LIBKETAMA_COMPATIBLE) == 1);
2122

2223
echo "test invalid options\n";
23-
error_reporting(0);
2424

2525
var_dump($m->setOptions(array(
2626
"asdf" => 123
2727
)));
28-
echo $php_errormsg, "\n";
2928

30-
$php_errormsg = '';
3129
var_dump($m->setOptions(array(
3230
-1 => 123
3331
)));
34-
echo $php_errormsg, "\n";
3532

3633
--EXPECTF--
3734
bool(true)
@@ -40,7 +37,9 @@ bool(true)
4037
bool(true)
4138
bool(true)
4239
test invalid options
40+
41+
Warning: Memcached::setOptions(): invalid configuration option in %s on line %d
4342
bool(false)
44-
%s::setOptions(): invalid configuration option
43+
44+
Warning: Memcached::setOptions(): error setting memcached option: %s in %s on line %d
4545
bool(false)
46-
%s::setOptions(): error setting memcached option: %s

0 commit comments

Comments
 (0)