Carbon: InvalidArgumentException : Unknown setter 'date’

Hello,

I have an issue with Carbon dates that are serialised through GitHub - opis/closure: Serialize closures (anonymous functions)

Laravel version: 6.11.0 Carbon version: 2.28.0 PHP version: 7.3.10 Opis/Closure version: 3.5.1

The problem seems to occur after upgrading to Laravel 6 and therefor upgraded from Carbon 1 to Carbon 2.

I wasn’t sure if this belongs to the Carbon or Opis issues. So I’ve posted this question on both. I will provide links later.

When a closure is serialized:

return serialize(new SerializableClosure($closure, true));

I get this error: InvalidArgumentException : Unknown setter 'date’.

This boils down to /nesbot/carbon/src/Carbon/Traits/Date.php:1166.

I’ve googled this issue for some time now and I believe it has got a lot to do with the depreciation of serializeUsing on Carbon 2. As found in issue Provide an alternative to serializeUsing to Laravel users · Issue #1870 · briannesbitt/Carbon · GitHub. @driesvints

However after reading multiple threats I’m not able to find a solution. I really hope someone can help me steering me to the right direction 🙏.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

Those 3 can work properly together if you install Carbon 2. If you have a constraint on Carbon 1, you can use an alias to enforce using the 2.x (See the doc). Version 1 is no longer maintained for a long time and will not receive such features updates.

If you are using Botman Studio, it uses Laravel 5.7 which is no longer supported neither and has security advisories: https://packagist.org/packages/laravel/framework/advisories?version=3782796

You will have more serious issues than the Carbon compatibility if you stay with Laravel < 7.23.2. As working on the compatibility issue from the Carbon side won’t be enough anyway, we won’t spend more time in it.

If you still have an issue with the last version of Carbon (and the rest of the stack pretty up to date), please open a proper issue following the pattern to detail precisely “when using Carbon”, dump the stack as text and provide a minimum code chunk that can allow me to reproduce the issue.

Thanks.

Hi @kylekatarnls, Thank you so much for this reply. I can completely understand now what is happening, why and where the responsibility lies for a solution. I love the Carbon package and use it every day. You’re awesome for providing this support even though it is not your responsibility in this case.

Thanks!