-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Cannot serialize IntlTimeZone objects #7939
Comments
It doesn't look like $tz = IntlTimeZone::createTimeZone('Europe/Amsterdam');
var_dump(serialize($tz));
But we could throw an error or at least emit some warning. |
Would it be difficult to implement serialization? Or do you worry about backwards compatibility? |
@drjayvee I know nothing about |
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.
I don't think it would be difficult, but what is the use case? I assume that |
I was under the admittedly naive assumption that every class supports serialization, unless it's especially tricky. Our particular use case is: class LocaleConfiguration {
public IntlTimeZone $timeZone = null;
public string $locale = 'en-US';
public int $firstWeekDay = 1;
// etc
} And then cache the user's configuration in their session, memory cache, or elsewhere. The simple yet awkward workaround is public function __serialize(): array {
return [
'timeZone' => $this->timeZone->getID(),
'locale' => $this->locale,
'firstWeekDay' => $this->firstWeekDay,
// etc
];
}
// reverse for __unserialize() |
Okay, for this case being able to (un)serialize Note, though, that a lot of internal classes don't support (un)serialization. |
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.
Serialization of these objects will be disallowed as of PHP 8.2.0. PRs to properly support (un)serialization (of individual classes) are welcome! |
Description
The following code:
Resulted in this output:
But I expected this output instead:
It looks like the implementation of
__serialize
is broken, as the string doesn't contain any object data:PHP Version
PHP 7.4.27 (cli) (built: Dec 21 2021 21:31:45) ( NTS )
Operating System
No response
The text was updated successfully, but these errors were encountered: