diff --git a/src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php b/src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php index 34bbeb8930078..02ebcfadf81a3 100644 --- a/src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php +++ b/src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php @@ -20,17 +20,15 @@ */ class DefaultMarshaller implements MarshallerInterface { - private bool $useIgbinarySerialize = true; + private bool $useIgbinarySerialize = false; private bool $throwOnSerializationFailure = false; public function __construct(?bool $useIgbinarySerialize = null, bool $throwOnSerializationFailure = false) { - if (null === $useIgbinarySerialize) { - $useIgbinarySerialize = \extension_loaded('igbinary') && version_compare('3.1.6', phpversion('igbinary'), '<='); - } elseif ($useIgbinarySerialize && (!\extension_loaded('igbinary') || version_compare('3.1.6', phpversion('igbinary'), '>'))) { + if ($useIgbinarySerialize && (!\extension_loaded('igbinary') || version_compare('3.1.6', phpversion('igbinary'), '>'))) { throw new CacheException(\extension_loaded('igbinary') ? 'Please upgrade the "igbinary" PHP extension to v3.1.6 or higher.' : 'The "igbinary" PHP extension is not loaded.'); } - $this->useIgbinarySerialize = $useIgbinarySerialize; + $this->useIgbinarySerialize = true === $useIgbinarySerialize; $this->throwOnSerializationFailure = $throwOnSerializationFailure; } diff --git a/src/Symfony/Component/Cache/Tests/Marshaller/DefaultMarshallerTest.php b/src/Symfony/Component/Cache/Tests/Marshaller/DefaultMarshallerTest.php index 45b7927861e26..a5578d963ab92 100644 --- a/src/Symfony/Component/Cache/Tests/Marshaller/DefaultMarshallerTest.php +++ b/src/Symfony/Component/Cache/Tests/Marshaller/DefaultMarshallerTest.php @@ -24,7 +24,27 @@ public function testSerialize() 'b' => function () {}, ]; - $expected = ['a' => \extension_loaded('igbinary') && (version_compare('3.1.6', phpversion('igbinary'), '<=')) ? igbinary_serialize(123) : serialize(123)]; + $expected = ['a' => serialize(123)]; + $this->assertSame($expected, $marshaller->marshall($values, $failed)); + $this->assertSame(['b'], $failed); + } + + /** + * @requires extension igbinary + */ + public function testIgbinarySerialize() + { + if (version_compare('3.1.6', phpversion('igbinary'), '>')) { + $this->markTestSkipped('igbinary needs to be v3.1.6 or higher.'); + } + + $marshaller = new DefaultMarshaller(true); + $values = [ + 'a' => 123, + 'b' => function () {}, + ]; + + $expected = ['a' => igbinary_serialize(123)]; $this->assertSame($expected, $marshaller->marshall($values, $failed)); $this->assertSame(['b'], $failed); }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: