Skip to content

Commit 0d879fc

Browse files
committed
feature symfony#57702 [Cache] Stop defaulting to igbinary in DefaultMarshaller (Martijn Croonen)
This PR was merged into the 7.2 branch. Discussion ---------- [Cache] Stop defaulting to `igbinary` in `DefaultMarshaller` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? |no | Issues | Fix symfony#52391 | License | MIT igbinary used to be a drop in replacement for PHP's `serialize` but recent changes (in PHP 7.4) to the handling of uninitialized properties in `serialize` have not made it into igbinary, so it no longer is a simple drop in replacement. This only removes igbinary as the default serializer, code can still opt-in through the first constructor argument. This may result in a performance regression on systems with igbinary as it would no longer be used by default. Fixes symfony#52391 Commits ------- 93c726d [Cache] Stop defaulting to igbinary in `DefaultMarshaller`
2 parents ce9fa75 + 93c726d commit 0d879fc

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
*/
2121
class DefaultMarshaller implements MarshallerInterface
2222
{
23-
private bool $useIgbinarySerialize = true;
23+
private bool $useIgbinarySerialize = false;
2424
private bool $throwOnSerializationFailure = false;
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+
if ($useIgbinarySerialize && (!\extension_loaded('igbinary') || version_compare('3.1.6', phpversion('igbinary'), '>'))) {
3129
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.');
3230
}
33-
$this->useIgbinarySerialize = $useIgbinarySerialize;
31+
$this->useIgbinarySerialize = true === $useIgbinarySerialize;
3432
$this->throwOnSerializationFailure = $throwOnSerializationFailure;
3533
}
3634

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

Lines changed: 21 additions & 1 deletion
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)