Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103830 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70780 invoked from network); 24 Jan 2019 18:02:22 -0000 Received: from unknown (HELO mail-io1-f53.google.com) (209.85.166.53) by pb1.pair.com with SMTP; 24 Jan 2019 18:02:22 -0000 Received: by mail-io1-f53.google.com with SMTP id k2so4884087iog.7 for ; Thu, 24 Jan 2019 06:40:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YGQ1WfE99xEdnln7j4yg4njrvqYjFKkEKIwi1fBm/ww=; b=T3ZskG0Xab+VAAWHWZ0LVRHaLJwhSuSYh9xTksiui+EhkY5iFJhRZhvF3mingGEvhJ MmDRjR6S1t5jBINJtQd33M4xXzmQbl7dicWsFrzPxmtE9KJ1ZNxHGN9QND1sWngItNLE YaexGGoVmrsmDRSD0WTgdMfnivOnDmzYytcvv7MDTomLs2cOkysU/gLiAJd0pv/wvCxh 4S3FCLXG+jmgZpQvv4R8iaGRYL3cH2NukhOwG5TyRCKtSePi47Q7E6wR6TXcs8ESB6nh I0izkjQWMpffTaDJ9eBXwALZ5wOPOWb9krhTnqvOaI0CMWK+qplZFFcCavENUkiX9plZ aErg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YGQ1WfE99xEdnln7j4yg4njrvqYjFKkEKIwi1fBm/ww=; b=lc9qR3pm+ai0Tk12jOpcVuStMDDxO325lo9DeYzUEgW/Uw3Tw/+QF+djMGiVeIfDut ZsZAjJ50ExkFptlVBe6AbrRwBl//glSKfh1MHosy56TwbtYMq252r3M4i3tYJbbt5hLf qDvEFYzQ9K2nWk8b1EaqPWrIxJ0974iM1rtJsJjJlFaKpbqUjo9UJ4b1ZAbTwjN4WK2X sIWXIGNdUVgDE6xDRSRqy+QYbbqToSW8v0mpU4KCRRj5eFd8W6QBdXyPuAJ3gJvPNHLI yntfuQryIrt0teNVQ/4fO1FiDLrQ2wyKekqSaaF0S2+LwDgzt6kK03DRW5ee3uJ40TYn NYAA== X-Gm-Message-State: AHQUAuZ8fsaByxWYdY235pMmMZZPusBal0VrkYkTDTjwcsrs+o01OLGj 5c1G0+ZzyeZuIExFjvDFGKeMIjl43DDN+xTyPhrHZw== X-Google-Smtp-Source: AHgI3IZHUmsIwLIVZ9cNxBB6UTAQnyW7dJyibF2NZPKDo/V8OX5eRNRjzuoWqRG6KZzjV3wFIeJ5Kf178p+zzDORHvI= X-Received: by 2002:a5d:834e:: with SMTP id q14mr3998714ior.258.1548340831586; Thu, 24 Jan 2019 06:40:31 -0800 (PST) MIME-Version: 1.0 References: <20190124131514.CD9051000DB@smtp02.mail.de> <96949d28-1b59-4d8b-9db7-6c5047d180f7@www.fastmail.com> In-Reply-To: <96949d28-1b59-4d8b-9db7-6c5047d180f7@www.fastmail.com> Date: Thu, 24 Jan 2019 15:40:15 +0100 Message-ID: To: Larry Garfield Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000420dae05803531c9" Subject: Re: [PHP-DEV] [RFC] New custom object serialization mechanism From: nikita.ppv@gmail.com (Nikita Popov) --000000000000420dae05803531c9 Content-Type: text/plain; charset="UTF-8" On Thu, Jan 24, 2019 at 3:08 PM Larry Garfield wrote: > On Thu, Jan 24, 2019, at 8:02 AM, Nicolas Grekas wrote: > > Thank you Nikita, > > > > the RFC looks solid to me. Using magic methods makes perfect sense to > allow > > a smooth migration path. > > > > We could enforce that if one of __serialize() or __unserialize() is > > > defined, both have to be defined, to avoid running into such cases. > > > > > > That would make sense a lot of sense to me. > > > > > > > Maybe one could use `__normalize()` and `__denormalize()` [...] > > > > > I'd like that "serialization" appears in some form in the name > > > > > > > An idea: __pre_serialize / __post_unserialize > > But __serialize/__unserialize are good to me. > > > > Nicolas > > Given that these methods would not be producing/consuming strings but a > de-classed representation of the object, I agree that it's closer to > "normalize" as Symfony uses the term. We don't have to use that name > specifically but something other than serialize/deserialize seems logical. > > Also, that in turn suggests that the same mechanism could be leveraged for > formats other than the C (or 0? It's referred to both ways in the RFC) > format we all know and grudgingly accept. Eg, it feels an awful lot like > JsonSerializable (which is for serialize only, but also returns an array), > and I can definitely see uses for a standard intermediary format that could > be encoded to C-serialized, JSON, or XML, or whatever else. Is there some > way that we could allow other systems to hook into it cleanly, such that it > becomes a common intermediary format for a variety of stringified formats? > Thanks for bringing this up. We do have a bit of a proliferation of different serialization-related (in the wider sense of the word) methods: * __sleep() and __wakeup() * Serializable * JsonSerializable * __set_state() It would be nice if we could make this reusable beyond serialization. There are two caveats that come to mind: * While __serialize() just returns an array, the same as JsonSerializable, this does not necessarily mean that they can be combined. PHP's serialization mechanism is much more powerful in what is can represent, so the return values of __serialize() and JsonSerializable::jsonSerialize() might well want to be different. The latter should in particular probably not include any non-trivial objects. * The __unserialize() method assumes an already constructed object on which __unserialize() can be called, which we need due to the peculiar limitations of serialization in PHP, but which is probably not very convenient for other purposes, where the approach of __set_state() is more useful. Nikita --000000000000420dae05803531c9--