Framework: Cache::many returns incorrect defaults

Created on 28 Apr 2017  Â·  6Comments  Â·  Source: laravel/framework

  • Laravel Version: 5.4.19
  • PHP Version: 7.0.15
  • Database Driver & Version: phpredis

Description:

Default values are only applied to null keys, not non-existing keys

Steps To Reproduce:

Cache::put('keyThatIsNull', null, 1);
dd(Cache::many([
    'keyThatIsNull' => 'You will see this string',
    'keyThatDoesNotExist' => 'But this default value does not work, you\'ll get false instead',
]));

output:

array:2 [
  "keyThatIsNull" => "You will see this string"
  "keyThatDoesNotExist" => false
]
bug

Most helpful comment

Ok I've opened a PR with a fix: https://github.com/laravel/framework/pull/18984

Thanks :)

All 6 comments

Where did you get this? many() accepts an array of keys with no default values.

since it wasn't in the docs for cache, I had to look through the source. Check out line 124:
https://github.com/illuminate/cache/blob/master/Repository.php

I see now, but I can't replicate your issue:

\Cache::put('keyThatIsNull', null, 1);

    dd(\Cache::many([
        'keyThatIsNull' => 'You will see this string',
        'keyThatDoesNotExist' => 'But this default value does not work, you\'ll get false instead',
    ]));

The results is:

array:2 [â–¼
  "keyThatIsNull" => "You will see this string"
  "keyThatDoesNotExist" => "But this default value does not work, you'll get false instead"
]

Are you using phpredis?

Ok I've opened a PR with a fix: https://github.com/laravel/framework/pull/18984

Thanks :)

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Demers94 picture Demers94  Â·  88Comments

ThomHurks picture ThomHurks  Â·  75Comments

GrahamCampbell picture GrahamCampbell  Â·  139Comments

JosephSilber picture JosephSilber  Â·  176Comments

thewinterwind picture thewinterwind  Â·  63Comments