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

ApcProxy::apc_add functionality is incorrect #30

Closed
fyrye opened this issue Apr 28, 2016 · 1 comment · Fixed by #31
Closed

ApcProxy::apc_add functionality is incorrect #30

fyrye opened this issue Apr 28, 2016 · 1 comment · Fixed by #31

Comments

@fyrye
Copy link
Contributor

fyrye commented Apr 28, 2016

Since apc_add and apc_store can accept a string or array for the key, when a string is supplied a var must also be applied, otherwise when key is an array it is handled as a key:var paired array

$cache->apc_add(['Hello' => 'World']); results in an exception being thrown.

public function apc_add($key, $var = null, $ttl = 0)
    {
        if (is_array($key) && $var === null) {
            throw new \InvalidArgumentException('When $key is set $var cannot be null');
        }

should be something like

public function apc_add($key, $var = null, $ttl = 0)
    {
        if (is_string($key) && $var === null) {
            throw new \InvalidArgumentException('When $key is set $var cannot be null');
        } elseif (is_array($key) && $var !== null) {
            throw new \InvalidArgumentException('When $key is an array $var must be null');
        }

reference: http://php.net/manual/en/function.apcu-add.php

@gordalina
Copy link
Owner

Very nice work debugging this, can you submit a pull request for this change?

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

Successfully merging a pull request may close this issue.

2 participants