Problem/Motivation
A fixture in a Layout Builder update path was causing unserialize errors only in PHP 7.3
See #3026698-44: Allow section storage to provide a more granular ID for tempstore
In order to write an update path, Layout Builder needed to provide a tempstore entry of a SectionStorage plugin.
This meant generating a serialized string representing that plugin.
After creating the serialized string, it was manually edited to change one value.
This caused no errors in PHP 7.2.
Also, this string was generated via a PHP script, not from within Drupal itself.
This may have affected the result.
Proposed resolution
Unserializing and serializing the fixture string from within a bootstrapped Drupal resulted in a slightly different string with the correct references intact.
This new string passes on both 7.2 and 7.3
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3033691-serialize-2.patch | 420 bytes | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #4
tim.plunkettThe error as reported by @tacituseu was
The part of the serialized string at offset 7543 was
r:248Now it reads
r:250I have NO idea what this part means.
a is array, b is Boolean, s is string, O is object. r could be reference, or resource, but idk what the number means. Anyway, from what I understand of the upstream PHP bug is that 7.3 is much more strict about enforcing that the string must be identical as if you were to unserialize it and reserialize.
Raising to critical for now because it breaks PHP 7.3 tests
Comment #5
tacituseu commented'r' means object reference (see: var.c, and var_unserializer.re)
Also, from https://bugs.php.net/bug.php?id=77302
Comment #6
tacituseu commentedThis rang a bell #3001920-25: Investigate PHP 7.3 workarounds.
Comment #7
tacituseu commentedThe difference is that in fixed version:
$obj->data['section_storage']->context['entity']->contextDefinition->labelis an object reference to$obj->data['section_storage']->context['entity']->contextData->definition->definition['label'], which is an instance of the classDrupal\Core\StringTranslation\TranslatableMarkupcontaining string"Content", both in PHP 7.2 and PHP 7.3.In the badly serialized version it is decoded by PHP 7.2 as a reference to the array
$obj->data['section_storage']->context['entity']->contextData->definition->definition[]and PHP 7.3 catches that and throws an exception.
It is the only encoded reference in that serialization string, so I'd say it is a proper fix.
Comment #8
xjmDiscussed this with @tim.plunkett; I am comfortable with the fix based on that explanation. Tim will update the IS with a bit more detail. Once that's done this can be set back to RTBC and it's good to go!
Comment #9
tim.plunkettComment #10
wim leersWow.
Comment #12
tim.plunkettInfra fail
Comment #14
xjmCommitted to 8.7.x. Thanks!
Comment #15
xjm