Skip to content

Commit 4924761

Browse files
author
Martijn Croonen
committed
[Cache] Stop defaulting to igbinary in DefaultMarshaller
igbinary used to be a drop in replacement for PHP's `serialize` but recent changes to the handling of uninitialized properties in `serialize` have not made it into igbinary, so it no longer is. Fixes #52391
1 parent d313221 commit 4924761

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ class DefaultMarshaller implements MarshallerInterface
2525

2626
public function __construct(?bool $useIgbinarySerialize = null, bool $throwOnSerializationFailure = false)
2727
{
28-
if (null === $useIgbinarySerialize) {
29-
$useIgbinarySerialize = \extension_loaded('igbinary') && version_compare('3.1.6', phpversion('igbinary'), '<=');
30-
} elseif ($useIgbinarySerialize && (!\extension_loaded('igbinary') || version_compare('3.1.6', phpversion('igbinary'), '>'))) {
28+
$useIgbinarySerialize = true === $useIgbinarySerialize;
29+
if ($useIgbinarySerialize && (!\extension_loaded('igbinary') || version_compare('3.1.6', phpversion('igbinary'), '>'))) {
3130
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.');
3231
}
3332
$this->useIgbinarySerialize = $useIgbinarySerialize;

src/Symfony/Component/Cache/Tests/Marshaller/DefaultMarshallerTest.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,27 @@ public function testSerialize()
2424
'b' => function () {},
2525
];
2626

27-
$expected = ['a' => \extension_loaded('igbinary') && (version_compare('3.1.6', phpversion('igbinary'), '<=')) ? igbinary_serialize(123) : serialize(123)];
27+
$expected = ['a' => serialize(123)];
28+
$this->assertSame($expected, $marshaller->marshall($values, $failed));
29+
$this->assertSame(['b'], $failed);
30+
}
31+
32+
/**
33+
* @requires extension igbinary
34+
*/
35+
public function testIgBinarySerialize()
36+
{
37+
if (version_compare('3.1.6', phpversion('igbinary'), '>')) {
38+
$this->markTestSkipped('igbinary needs to be v3.1.6 or higher.');
39+
}
40+
41+
$marshaller = new DefaultMarshaller(true);
42+
$values = [
43+
'a' => 123,
44+
'b' => function () {},
45+
];
46+
47+
$expected = ['a' => igbinary_serialize(123)];
2848
$this->assertSame($expected, $marshaller->marshall($values, $failed));
2949
$this->assertSame(['b'], $failed);
3050
}

0 commit comments

Comments
 (0)