Open
Description
Describe the bug
I'm using the cache adapter Memory
. When I call the method $cache->get('key')
, I get the following error message from PHP:
PHP Notice: Undefined index: ph-memo-key in phalcon/Storage/Adapter/Memory.zep on line 232 in ./test.php on line 12
PHP Stack trace:
PHP 1. {main}() .../test.php:0
PHP 2. Phalcon\Cache\Cache->get($key = 'key') ./test.php:12
PHP 3. Phalcon\Cache\AbstractCache->doGet($key = 'key', $defaultValue = NULL) ./test.php:12
PHP 4. Phalcon\Storage\Adapter\AbstractAdapter->get($key = 'key', $defaultValue = NULL)./test.php:12
PHP 5. Phalcon\Storage\Adapter\Memory->doGet($key = 'key') ./test.php:12
To Reproduce
Content from the test.php file.
<?php
use Phalcon\Cache\AdapterFactory;
use Phalcon\Cache\CacheFactory;
use Phalcon\Storage\SerializerFactory;
$serializerFactory = new SerializerFactory();
$adapterFactory = new AdapterFactory($serializerFactory);
$cacheFactory = new CacheFactory($adapterFactory);
$cache = $cacheFactory->newInstance('memory', []);
$data = [1, 2, 3];
$cacheData = $cache->get('key'); // This line triggers the error.
Phalcon file
PHP code from file (line 225-233) ./phalcon/Storage/Adapter/Memory.zep
:
/**
* @param string $key
*
* @return mixed
*/
protected function doGet(string key)
{
return this->data[this->getPrefixedKey(key)];
}
Suggestion
/**
* @param string $key
*
* @return mixed
*/
protected function doGet(string key)
{
if (array_keys_exists(this->getPrefixedKey(key), this->data) {
return this->data[this->getPrefixedKey(key)];
}
return false;
}
Details
- Phalcon version: 5.9.3
- PHP Version: 8.3.23
- Operating System: Linux Mint
- Installation type: Download from Github releases
- Zephir version (if any):
- Server: Apache
- Other related info (Database, table schema): MySQL