Skip to content

Serializing DatePeriod in v2 and unserializing in v3 #36

@mcop1

Description

@mcop1

Hello,

after upgrading from v2 to v3.9.1, we've encountered an issue with previously serialized CarbonPeriod objects. Specifically, attempting to unserialize these objects now results in an error:

Cannot modify readonly property DatePeriod::$current.

Short example to reproduce the issue:

//serialized data from v2
$data = 'O:19:"Carbon\CarbonPeriod":24:{s:12:" * dateClass";s:13:"Carbon\Carbon";s:15:" * dateInterval";O:21:"Carbon\CarbonInterval":22:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:3;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:6:"invert";i:0;s:4:"days";b:0;s:11:"from_string";b:0;s:9:" * tzName";N;s:7:" * step";N;s:22:" * localMonthsOverflow";N;s:21:" * localYearsOverflow";N;s:25:" * localStrictModeEnabled";N;s:24:" * localHumanDiffOptions";N;s:22:" * localToStringFormat";N;s:18:" * localSerializer";N;s:14:" * localMacros";N;s:21:" * localGenericMacros";N;s:22:" * localFormatFunction";N;s:18:" * localTranslator";N;}s:14:" * constructed";b:1;s:20:" * isDefaultInterval";b:0;s:10:" * filters";a:1:{i:0;a:2:{i:0;a:2:{i:0;s:19:"Carbon\CarbonPeriod";i:1;s:13:"filterEndDate";}i:1;N;}}s:12:" * startDate";O:13:"Carbon\Carbon":3:{s:4:"date";s:26:"2018-04-21 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}s:10:" * endDate";O:13:"Carbon\Carbon":3:{s:4:"date";s:26:"2018-04-27 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}s:14:" * recurrences";N;s:10:" * options";i:0;s:6:" * key";N;s:10:" * current";N;s:11:" * timezone";N;s:19:" * validationResult";N;s:9:" * tzName";N;s:22:" * localMonthsOverflow";N;s:21:" * localYearsOverflow";N;s:25:" * localStrictModeEnabled";N;s:24:" * localHumanDiffOptions";N;s:22:" * localToStringFormat";N;s:18:" * localSerializer";N;s:14:" * localMacros";N;s:21:" * localGenericMacros";N;s:22:" * localFormatFunction";N;s:18:" * localTranslator";N;}';

$period = unserialize($data);

Found a similar issue here briannesbitt/Carbon#3015, any suggestions on how to resolve this?

Best regards

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions