Sorry, forgot to CC the following mail to internals:
Am 24-Jan-2019 14:28:43 +0100 schrieb nikita.ppv@gmail.com:
On Thu, Jan 24, 2019 at 13:27 Nikita Popov nikita.ppv@gmail.com
wrote:Hi internals,
I'd like to propose a new custom object serialization mechanism intended to
replace the broken Serializable interface:https://wiki.php.net/rfc/custom_object_serialization
This was already previously discussed in https://externals.io/message/98834,
this just brings it into RFC form. The latest motivation for this is
https://bugs.php.net/bug.php?id=77302, a compatibility issue in 7.3
affecting Symfony, caused by Serializable. We can't fix Serializable, but
we can at least make sure that a working alternative exists.Regards,
NikitaHi.
What happens if both
__serialize()
and__wakeup()
are implemented?You mean if there are just those two methods, but not __unserialize() for example?
In that case the array returned by __serialize() will be unserialized as object
properties and __wakeup() will be called for finalization. In principle it's okay to
use this combination, though it would be somewhat unusual.
Sorry, what I wanted to ask was, what happens if __serialize()
and __SLEEP()
are implemented? xD
Here's an example:
class A {
private $foo = 'foo';
private $bar = 'bar';
function __serialize() {
return ['foo' => $this->foo];
}
function __sleep() {
return ['bar'];
}
}
echo serialize(new A());
What will be the output of the above snippet?
And another idea for the naming: Maybe one could use
__normalize()
and__denormalize()
. Because the methods do not serialize themself, like the normalizer in the Symfony serializer component.I'd like that "serialization" appears in some form in the name, to make clear in what context this is used. Normalization is a fairly general term and could refer to any number of things.
Nikita
Yes, you are right. It is just, that my personal taste for function names is that they should describe what they do. New users may be irritated about the function name.
Maybe a more explicit name would be __toSerializable
.
But I have no idea for the counterpart ^^
Best regards,
Christian
FreeMail powered by mail.de - MEHR SICHERHEIT, SERIOSITÄT UND KOMFORT
Sorry, what I wanted to ask was, what happens if
__serialize()
and
__SLEEP()
are implemented? xD
This is covered in the RFC:
If a class has both __sleep() and __serialize(), then the latter will be
preferred.
In other words, if both are included, only __serialize() will be run by PHP
= 7.4 (but __sleep() will be called by PHP <= 7.3, providing an upgrade
path).
Regards,
Rowan Collins
[IMSoP]