src/includes/traits/CacheMembers.php
protected function &cacheKey(string $primary_key, $args = [])
    {
        $args = (array) $args; // Force an array of args.

        if (!isset($this->x___cache['x___keys'][$primary_key])) {
            $this->x___cache['x___keys'][$primary_key] = null;
        }
        $cache_key = &$this->x___cache['x___keys'][$primary_key];

        foreach ($args as $_arg) {
            switch (($_arg_type = gettype($_arg))) {
                case 'int':
                case 'integer':
                    $_key = (int) $_arg;
                    // Only integer key.
                    break; // Break switch handler.

                case 'double':
                case 'float':
                case 'real':
                    $_key = (string) $_arg;
                    // Only numeric string.
                    break; // Break switch handler.

                case 'bool':
                case 'boolean':
                    $_key = $_arg ? 'true' : 'false';
                    // Only string not sha1 or numeric.
                    break; // Break switch handler.

                case 'string':
                    $_key = sha1($_arg_type.$_arg);
                    break; // Break switch handler.

                case 'array':
                    $_key = sha1($_arg_type.serialize($_arg));
                    break; // Break switch handler.

                case 'object': // See: <http://php.net/manual/en/function.spl-object-hash.php>
                    $_key = spl_object_hash($_arg).sha1($_arg_type.get_class($_arg).serialize($_arg));
                    break; // Break switch handler.

                case 'null':
                case 'NULL':
                case 'resource':
                case 'unknown':
                case 'unknown type':
                    $_key = "\0".sha1($_arg_type.(string) $_arg);
                    break; // Break switch handler.

                default: // Default case handler.
                    throw $this->c::issue(sprintf('Unexpected arg type: `%1$s`.', $_arg_type));
            }
            if (!isset($cache_key[$_key])) {
                $cache_key[$_key] = null;
            }
            $cache_key = &$cache_key[$_key];
        } // unset($_arg, $_arg_type, $_key);

        return $cache_key;
    }
protected function &cacheKey(string $primary_key, $args = [])
    {
        $args = (array) $args; // Force an array of args.

        if (!isset($this->x___cache['x___keys'][$primary_key])) {
            $this->x___cache['x___keys'][$primary_key] = null;
        }
        $cache_key = &$this->x___cache['x___keys'][$primary_key];

        foreach ($args as $_arg) {
            switch (($_arg_type = gettype($_arg))) {
                case 'int':
                case 'integer':
                    $_key = (int) $_arg;
                    // Only integer key.
                    break; // Break switch handler.

                case 'double':
                case 'float':
                case 'real':
                    $_key = (string) $_arg;
                    // Only numeric string.
                    break; // Break switch handler.

                case 'bool':
                case 'boolean':
                    $_key = $_arg ? 'true' : 'false';
                    // Only string not sha1 or numeric.
                    break; // Break switch handler.

                case 'string':
                    $_key = sha1($_arg_type.$_arg);
                    break; // Break switch handler.

                case 'array':
                    $_key = sha1($_arg_type.serialize($_arg));
                    break; // Break switch handler.

                case 'object': // See: <http://php.net/manual/en/function.spl-object-hash.php>
                    $_key = spl_object_hash($_arg).sha1($_arg_type.get_class($_arg).serialize($_arg));
                    break; // Break switch handler.

                case 'null':
                case 'NULL':
                case 'resource':
                case 'unknown':
                case 'unknown type':
                    $_key = "\0".sha1($_arg_type.(string) $_arg);
                    break; // Break switch handler.

                default: // Default case handler.
                    throw $this->c::issue(sprintf('Unexpected arg type: `%1$s`.', $_arg_type));
            }
            if (!isset($cache_key[$_key])) {
                $cache_key[$_key] = null;
            }
            $cache_key = &$cache_key[$_key];
        } // unset($_arg, $_arg_type, $_key);

        return $cache_key;
    }
Cache key (or sub-key) based on args.

@since 150424 Initial release.

@param string      $primary_key Primary key.
@param mixed|array $args        Args to base key on.

@return mixed|null Value (by reference) for the cache key. Default is `null`.

@internal Returns by reference. The use of `&` is highly recommended when calling this utility.
See also: <http://php.net/manual/en/language.references.return.php>