phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.79k stars 1.96k forks source link

[BUG]: Phalcon\Storage\Serializer\Igbinary not saving is_numeric()/bool values #15240

Closed Aphexx closed 3 years ago

Aphexx commented 3 years ago

Describe the bug The Igbinary serializer storage adapter is not saving bool and is_numeric() values, because of isSerializable() check at Phalcon\Storage\Serializer\Igbinary->serialize() function.

https://github.com/phalcon/cphalcon/blob/3241d96e4bb01dc7746b74c9ce586250b8887c46/phalcon/Storage/Serializer/Igbinary.zep#L20 isSerializable() function checks for is_numeric/boolean in value that need to be saved and skips igbinary_serialize() for it. After that raw value fails to igbinary_unserialize() and cache->get() returns null.

POC

$apcCache = new \Phalcon\Cache\Adapter\Apcu(new \Phalcon\Storage\SerializerFactory(), [
            'defaultSerializer' => 'Igbinary',
]);

$key = 'cache-key';
$val = '100';
$apcCache->set($key, $val, 10);
var_dump($val);   // 100
var_dump($this->apcCache->get($key)); // null  <------- SHOULD BE SAME VALUE

// Correct cache save/retrieve with non numeric string 
$val = 'i_am_string';
$apcCache->set($key, $val, 10);
var_dump($val);   // i_am_string
var_dump($this->apcCache->get($key)); // i_am_string <---- correct behavior

image

Solution All values should be serialized with igbinary_serialize(). Remove isSerializable() check from Phalcon\Storage\Serializer\Igbinary->serialize() function.

Details Phalcon version: 4.1.0 PHP Version: PHP 7.3 Zephir version (if any): No

niden commented 3 years ago

@Aphexx Thank you for reporting this.

Resolved in https://github.com/phalcon/cphalcon/pull/15342