briannesbitt / Carbon

A simple PHP API extension for DateTime.

Home Page:https://carbon.nesbot.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serialization of 'Closure' is not allowed

alvaronds opened this issue · comments

Hello,

I encountered an issue with the following code:

If I try to serializate a CarbonInterval I can without problems:

$a = new CarbonInterval(1);
$b = serialize($a);

But if the CarbonInterval has been generated with diffAsCarbonInterval I get an "Serialization of 'Closure' is not allowed" error.

$a = Carbon::now();
$b = Carbon::now()->addDay();
$c = $a->diffAsCarbonInterval($b);
$d = serialize($c);

I also have problems unserializing saved CarbonIntervals generated with Carbon 2 in Laravel. I need to do this to unserialize them:

str_replace('tzName','timezoneSetting',$mySavedCarbonInterval);

Carbon version: 3.3.0

PHP version: 8.3.4

I expected to get:

The serialized CarbonInterval

But I actually get:

PHP ERROR: Serialization of 'Closure' is not allowed

I tried the code in the https://play.phpsandbox.io and fails with Carbon 3. Carbon 2 works great

Thanks!

commented

Serialization of CarbonInterval is now possible in 3.3.1.

commented

Unserialization of Carbon v2 interval will be handled in a separated issue: #3015