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

Cache::many returns incorrect defaults #18981

Closed
Dadibom opened this issue Apr 28, 2017 · 6 comments
Closed

Cache::many returns incorrect defaults #18981

Dadibom opened this issue Apr 28, 2017 · 6 comments
Labels

Comments

@Dadibom
Copy link

Dadibom commented Apr 28, 2017

  • 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
]
@themsaid
Copy link
Member

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

@Dadibom
Copy link
Author

Dadibom commented Apr 28, 2017

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

@themsaid
Copy link
Member

themsaid commented Apr 28, 2017

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"
]

@Dadibom
Copy link
Author

Dadibom commented Apr 28, 2017

Are you using phpredis?

@themsaid
Copy link
Member

Ok I've opened a PR with a fix: #18984

Thanks :)

@Dadibom
Copy link
Author

Dadibom commented Apr 28, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants