From 3baac953bf9b8d5719ea05dd092ea83016cff4a9 Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Sat, 28 Nov 2026 05:19:14 +0000 Subject: [PATCH 1/2] [apcu] Clarify apcu_fetch() behaviour when an array of keys is given The return values section described the result as "the stored variable or array of variables", which suggested that apcu_fetch() would somehow create variables, and did not explain what is actually returned for an array of keys. Document the behaviour as implemented in php_apc.c: - when key is an array, an associative array mapping each key found in the cache to its value is returned, and missing keys are omitted; - in that case the success parameter is always set to true, even if none of the keys exist; - since false can be stored as a value, success is the way to tell a stored false apart from a failure. Also type the key parameter as string|array instead of mixed, matching the extension stub, describe the function in terms of values rather than variables, and add an example fetching several entries at once and destructuring the result. Fixes #19 --- reference/apcu/functions/apcu-fetch.xml | 59 ++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/reference/apcu/functions/apcu-fetch.xml b/reference/apcu/functions/apcu-fetch.xml index d394f819c..20c4c9789 100644 --- a/reference/apcu/functions/apcu-fetch.xml +++ b/reference/apcu/functions/apcu-fetch.xml @@ -4,14 +4,14 @@ apcu_fetch - Fetch a stored variable from the cache + Fetch a stored value from the cache &reftitle.description; mixedapcu_fetch - mixedkey + stringarraykey boolsuccess @@ -26,8 +26,9 @@ The key used to store the value (with - apcu_store). If an array is passed then each - element is fetched and returned. + apcu_store). If an array of keys is passed then + each key is fetched, and the entries which are found in the cache are + returned as an array. @@ -35,7 +36,9 @@ success - Set to &true; in success and &false; in failure. + Set to &true; on success and &false; on failure. If + key is an array, it is always set to &true;, + even if none of the keys exist in the cache. @@ -44,8 +47,21 @@ &reftitle.returnvalues; - The stored variable or array of variables on success; &false; on failure + If key is a string, returns the stored value on + success, or &false; on failure. + + If key is an array, returns an associative array + which maps each key found in the cache to its stored value. Keys that do + not exist in the cache are omitted from the returned array. + + + + As &false; can also be stored as a value, use the + success parameter to distinguish a stored &false; + from a failure. + + @@ -87,6 +103,37 @@ var_dump(apcu_fetch('foo')); + + + + Fetching multiple entries with <function>apcu_fetch</function> + + 13, 'rate' => 22]); + +$values = apcu_fetch(['progress', 'rate', 'missing'], $success); +var_dump($values, $success); + +// The returned array can be destructured into variables +['progress' => $progress, 'rate' => $rate] = $values; +var_dump($progress, $rate); +?> +]]> + + &example.outputs; + + + int(13) + ["rate"]=> + int(22) +} +bool(true) +int(13) +int(22) ]]> From 3bcebfeb7ef6a023d8dea60b936927d9d6bed5ac Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Sun, 29 Nov 2026 00:28:31 +0530 Subject: [PATCH 2/2] [apcu] Document skipped non-string keys and false return of apcu_fetch() Mention that non-string elements of an array of keys are skipped with an E_WARNING, and state that a string key returns false when the entry does not exist in the cache or has expired. --- reference/apcu/functions/apcu-fetch.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/reference/apcu/functions/apcu-fetch.xml b/reference/apcu/functions/apcu-fetch.xml index 20c4c9789..efee26a6b 100644 --- a/reference/apcu/functions/apcu-fetch.xml +++ b/reference/apcu/functions/apcu-fetch.xml @@ -28,7 +28,8 @@ The key used to store the value (with apcu_store). If an array of keys is passed then each key is fetched, and the entries which are found in the cache are - returned as an array. + returned as an array. Array elements that are not strings are skipped + and an E_WARNING is raised. @@ -47,8 +48,8 @@ &reftitle.returnvalues; - If key is a string, returns the stored value on - success, or &false; on failure. + If key is a string, returns the stored value, or + &false; if the key does not exist in the cache or has expired. If key is an array, returns an associative array