Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 5.6.7 Redis::scan() expected to be a reference #178

Closed
ddproxy opened this issue Apr 14, 2015 · 8 comments
Closed

PHP 5.6.7 Redis::scan() expected to be a reference #178

ddproxy opened this issue Apr 14, 2015 · 8 comments

Comments

@ddproxy
Copy link

ddproxy commented Apr 14, 2015

I'm getting the following error:

Warning: Parameter 1 to Redis::scan() expected to be a reference, value given

With the following code:

public function getCacheAction(Request $request, ParamFetcherInterface $paramFetcher)
{
    $redis = $this->container->get('snc_redis.data');
    $it = NULL; 
    $redis->setOption(\Redis::OPT_SCAN, \Redis::SCAN_RETRY); 
    while($arr_keys = $redis->scan($it)) {
        $array[] = $arr_keys;
    }
    return $array;
}

I'm using Symfony 2.6 and Redis Extension 2.2.7

I've narrowed down a possible cause of this issue.

Client\Phpredis\BaseClient

public function __call($name, array $arguments)
{
    if (null === $this->redis) {
        throw new \RuntimeException('You have to define a Redis instance before calling any command.');
    }

    return call_user_func_array(array($this->redis, $name), $arguments);
}

http://php.net/manual/en/function.call-user-func-array.php

Note:
Before PHP 5.4, referenced variables in param_arr are passed to the function by reference, regardless of whether the function expects the respective parameter to be passed by reference. This form of call-time pass by reference does not emit a deprecation notice, but it is nonetheless deprecated, and has been removed in PHP 5.4.

Without SncRedisBundle and using the Redis object directly,

$redis = new \Redis();
$redis->connect('127.0.0.1',6379);
$redis->select(2);
$it = NULL; /* Initialize our iterator to NULL */
$redis->setOption(\Redis::OPT_SCAN, \Redis::SCAN_RETRY); /* retry when we get no keys back */
$array = [];
while($arr_keys = $redis->scan($it)) {
    $array[] = $arr_keys;
}
return $array;

I get my expected return.

@luishdez
Copy link

luishdez commented Sep 6, 2015

Yep same problem

@ddproxy
Copy link
Author

ddproxy commented Sep 6, 2015

I'm not using scan anymore so I can't test of this is still an issue.

@luishdez - what version php, snc, and redis extension are you using?

@romaincorral
Copy link

I'm the same problem with :

  • php 5.5.9-1ubuntu4.14
  • redis 2.8.4
  • phpredis 2.2.7
  • snc/redis-bundle 1.1.x-dev

@luishdez
Copy link

luishdez commented Mar 10, 2016

@ddproxy Sorry I missed the comment I've used the next versions:

php 5.6.19 also tested with 7
redis 2.8 and 3.0.7
phpredis 2.2.6 and 2.2.7
snc/redis-bundle 1.1.10 also tested with dev-master

@GeoffroyR
Copy link

GeoffroyR commented Aug 17, 2016

If you still want to use snc (for the logs, connections,..) you can call the scan method trough call_user_func_array to pass the argument by reference:

$redis = $this->container->get('snc_redis.data');
$iterator = null;
$arguments = array(&$iterator);
call_user_func_array(array($redis, 'scan'), $arguments));

@quentin-st
Copy link
Contributor

@GeoffroyR 's workaround doesn't work for me. Will this issue be fixed?

@abguy
Copy link

abguy commented Dec 22, 2016

I have the same issue on PHP 7.0

toooni added a commit to toooni/SncRedisBundle that referenced this issue Jan 18, 2017
Solves issue `Warning: Parameter 1 to Redis::scan() expected to be a reference, value given` in snc#178
@toooni
Copy link
Contributor

toooni commented Jan 26, 2017

@ddproxy @luishdez @romaincorral @GeoffroyR @chteuchteu @abguy this works now and can be closed!

@snc snc closed this as completed Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants