bug #29591 [Cache] Fix undefined variable in ArrayTrait (eXtreme)

This PR was merged into the 4.2 branch.

Discussion
----------

[Cache] Fix undefined variable in ArrayTrait

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

After upgrading my project to 4.2 my tests failed with a message that `$key` variable is missing here: e81285249b/src/Symfony/Component/Cache/Traits/ArrayTrait.php (L131) which seems to be introduced with PR https://github.com/symfony/symfony/pull/27563.

So I added that variable to the trait and method calls (are there any other?). This is internal class so I guess noone is using it anywhere.

Anyway, my tests pass with this fix.

Commits
-------

b0b5937d1d Fix undefined variable in cache ArrayTrait
This commit is contained in:
Nicolas Grekas 2018-12-13 14:38:51 +01:00
commit 0d2fb4b977
3 changed files with 3 additions and 3 deletions

View File

@ -124,7 +124,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
return true;
}
if ($this->storeSerialized && null === $value = $this->freeze($value)) {
if ($this->storeSerialized && null === $value = $this->freeze($value, $key)) {
return false;
}
if (null === $expiry && 0 < $item["\0*\0defaultLifetime"]) {

View File

@ -129,7 +129,7 @@ class ArrayCache implements CacheInterface, LoggerAwareInterface, ResettableInte
$expiry = 0 < $ttl ? microtime(true) + $ttl : PHP_INT_MAX;
foreach ($valuesArray as $key => $value) {
if ($this->storeSerialized && null === $value = $this->freeze($value)) {
if ($this->storeSerialized && null === $value = $this->freeze($value, $key)) {
return false;
}
$this->values[$key] = $value;

View File

@ -113,7 +113,7 @@ trait ArrayTrait
}
}
private function freeze($value)
private function freeze($value, $key)
{
if (null === $value) {
return 'N;';