Skip to content

Commit 319afe0

Browse files
committed
Fix ($subject) must be of type array|string, null given
1 parent 7308f43 commit 319afe0

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/SWP/Bundle/CoreBundle/Migrations/2021/01/Version20210112135542.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,29 @@ public function postUp(Schema $schema): void
119119
}
120120
}
121121

122-
private function unserializeExtraField(string $data)
122+
private function unserializeExtraField(?string $data)
123123
{
124-
$data = @unserialize($data);
125-
if ($data) {
126-
return $data;
124+
// Handle null or empty data
125+
if (empty($data)) {
126+
return null;
127127
}
128128

129+
$unserializedData = @unserialize($data);
130+
if ($unserializedData !== false) {
131+
return $unserializedData;
132+
}
133+
134+
// If unserialize failed, try to fix and retry
129135
$callback = function ($matches) {
130136
$matches[2] = trim(preg_replace('/\s\s+/', ' ', $matches[2]));
131137
return 's:' . mb_strlen($matches[2]) . ':"' . $matches[2] . '";';
132138
};
133139

134140
$data = preg_replace_callback('!s:(\d+):"(.*?)";!s', $callback, $data);
141+
if ($data === null) {
142+
return null;
143+
}
144+
135145
return @unserialize($data);
136146
}
137147
}

0 commit comments

Comments
 (0)