Skip to content

Fix GH-7939: Cannot unserialize IntlTimeZone objects #7945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jan 15, 2022

As it is now, IntlTimeZone, IntlCalendar and IntlDateFormatter
instances can be serialized, but the representation is meaningless, and
unserialization yields uninitialized/unusable objects. To prevent
users from noticing this too late, we deny serialization of such
objects in the first place.


Note that I targetted PHP-8.1 for convenience, and that I didn't check other Intl classes for now which may have the same issue. For now, I'm interested whether we want to go this route (note that any serialization attempt will throw an Error now), or whether we actually want to implement proper (un)serialization for these classes.

@cmb69 cmb69 marked this pull request as draft January 15, 2022 13:17
@cmb69 cmb69 linked an issue Jan 15, 2022 that may be closed by this pull request
@iluuu1994
Copy link
Member

The downside is that this would make the whole serialization fail for cases where IntlTimeZone might be embedded in a nested structure but otherwise disregarded.

@cmb69
Copy link
Member Author

cmb69 commented Jan 17, 2022

@iluuu1994, indeed. But the alternatives would be to implement proper (un)serialization (not sure if feasible for all Intl classes), or to only issue E_WARNING (what might be converted to an exception by the error handler), or to keep it as is (what might be the worst option). Or are there other options?

@iluuu1994
Copy link
Member

iluuu1994 commented Jan 17, 2022

@cmb69 I think making it non-serializable is ok but might be a bit disruptive for a patch. Then again I have very little experience with PHP releases so you probably know better than me 😄

As it is now, `IntlTimeZone`, `IntlCalendar` and `IntlDateFormatter`
instances can be serialized, but the representation is meaningless, and
unserialization yields uninitialized/unusable objects.  To prevent
users from noticing this too late, we deny serialization of such
objects in the first place.
@cmb69 cmb69 changed the base branch from PHP-8.1 to master January 18, 2022 14:42
@cmb69
Copy link
Member Author

cmb69 commented Jan 18, 2022

Okay, makes sense. I've retargeted to "master".

Apparently, (un)serialization support has been completely overlooked
for ext/intl.
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are also not serializable:

  • IntlCalendar
  • IntlGregorianCalendar
  • IntlDatePatternGenerator
  • Locale (should __construct also be private as this is supposed to be a static class?)
  • Normalizer (same as above)
  • IntlChar (same as above)

@cmb69
Copy link
Member Author

cmb69 commented Jan 19, 2022

Thanks for checking, @iluuu1994!

IntlCalendar and IntlGregorianCalendar are already covered (1st commit). Locale, Normalizer and IntlChar are indeed static classes, so their constructor should be private; serialization "works" though; I see that as a different topic (as well as IntlIterator not being abstract, although you can't use any of its instances). I shall catch up on IntlDatePatternGenerator (which it is not yet documented).

@iluuu1994
Copy link
Member

Alright, I think if we make IntlDatePatternGenerator non-serializable (as it does store the locale and thus won't work if unserialized) this PR should be ready.

@cmb69
Copy link
Member Author

cmb69 commented Jan 20, 2022

The CI fails appear to be unrelated.

@cmb69 cmb69 marked this pull request as ready for review January 20, 2022 11:09
Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot serialize IntlTimeZone objects
2 participants