Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103859 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23332 invoked from network); 28 Jan 2019 11:52:28 -0000 Received: from unknown (HELO mail-ot1-f67.google.com) (209.85.210.67) by pb1.pair.com with SMTP; 28 Jan 2019 11:52:28 -0000 Received: by mail-ot1-f67.google.com with SMTP id k98so13944136otk.3 for ; Mon, 28 Jan 2019 00:31:33 -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=86Rx8M+XaZ1PN/b8QI+3Ha7784NoxwPzFidbUMBjTN4=; b=eIFcchivLOThwT3Q2bh9lipLEkNtqywiHLtvr61vN6j/ZwZNfsAotU6elzL/oxZBvl zgeXbUhw9KBZsxtD7KmM8vFlTQ+UF7LOfJUl6tA4Q6Gy7+IZPom+V+FEhwsS0bHlBcI5 ePZHSbMl076ZatQkdRZz4fivqo2ZniaLOUgUuHzEKDMU1Y6/vTUzc402NjdQOh8nsKUz 1brO78mFZMzwT7cda91VwXuLdKCuaXckfMzlk/hTcDSKSu1R3XPObnO06q0OsHxRsath mefvP2P2dpw4K+bHWQUKr32QLIwYinXmsDBGyekDYnTs/HAiTTFisNRdTHdK48VDGxkp UjxA== 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=86Rx8M+XaZ1PN/b8QI+3Ha7784NoxwPzFidbUMBjTN4=; b=LJsafOJ8ldD+JfBNd8CcFzJzbaFlheDPBygWYmf2tkzgEJe8m3LjfqcnUQvqYCTzdz OmcV/7dDCRgcJuallNT44u/DY6FonjKntUznrCDzHlTtrgckV6L66X1NWNrTdPsV3fx6 T6np/lI89J/QG6Xz7K1ZWYGjpe4PxsndBIuBVDz5MKG2jllNRVcXQxbqdfHELp1Wopm7 RvI9T0IdBFQER9YQYf+H8uNt/UN7QldMl5aM3tlA/oFdf4d9Z2MhkYfuJeG8qtBSnBl3 QgwUBTXQWPCvS6Rh6UpqUQ+kWbM/wgIKdjktLedeGACDDktdsQADBkf8J1r6iRYvcgIj rBVQ== X-Gm-Message-State: AJcUukdVHUtts9qroa9POY0VRIOdW4hx1FTS0qBeMA/ZdK3i8ifMPYjo 9DCJtrvmnQBJyJG6AZlSY+n8rJ5CEypohrbIPcU= X-Google-Smtp-Source: ALg8bN6NhN/0Cl6YWudyk8430TNBTLceEuwzlJNs85mKzC61r6gIZThGM5lw9d93GWdF/P1/m0cRC89IEbvOcHQJ7b4= X-Received: by 2002:a05:6830:2010:: with SMTP id e16mr14933977otp.86.1548664292939; Mon, 28 Jan 2019 00:31:32 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 28 Jan 2019 09:31:21 +0100 Message-ID: To: Marco Pivetta Cc: Sebastian Bergmann , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000000e9b5905808081e5" Subject: Re: [PHP-DEV] [RFC] New custom object serialization mechanism From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --0000000000000e9b5905808081e5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable (I should have reviewed myself in the first message - sentences edited in this reply) Le lun. 28 janv. 2019 =C3=A0 08:58, Marco Pivetta a = =C3=A9crit : > On Sun, Jan 27, 2019 at 5:37 PM Nicolas Grekas < > nicolas.grekas+php@gmail.com> wrote: > >> Le jeu. 24 janv. 2019 =C3=A0 15:18, Sebastian Bergmann a >> =C3=A9crit : >> >> > Am 24.01.2019 um 15:09 schrieb Marco Pivetta: >> > > Not really fussed about having another implicit interface for >> > serialization >> > > (via magic methods). >> > >> > I second that emotion. >> > >> >> >> The more I think about it, the more I'm convinced we should *not* add an >> interface for that. >> An interface defines a semantics - an API to a domain - and >> that ppl can type-hint for to get a specific implementation of that >> API. > > > An interface declares an API surface for an object: in this case, the > consumer would be `serialize()` or `unserialize()`, and that's a perfectl= y > valid use-case scenario. > Implemeting serialize/unserialize methods is meant to hook into the same-name functions. That's a very technical and concrete thing - a behavior - not anything abstract as an interface is. Here, both aspects are not desired: we don't want ppl to type-hint for >> e.g. Serializable - and too bad it exists because I've already seen ppl >> think: "hey, I'll type-hint or extend it to express I want a serializabl= e >> thing". > > > That's actually a very correct thing to do: by declaring that something i= s > `Serializable`, you are expressing your intent to anybody inspecting the > structure of the object. > "intent" is the issue here: these is no such abstract thing here. The PHP engine is a very concrete object that provides behaviors to userland. And we need a proper hook to configure the behavior of the serialize/unserialize functions. There is no such things as interface/intent/abstraction here, just a hook and that's perfect because the engine should define as little semantics as possible: that's the job of userland! BUT that's *not* the contract of Serializable or any variant of it >> because: 1. *any* PHP object is serializable 2. Serializable it well >> allowed to throw an exception to exactly *forbid* an object from being >> serialized. >> > > That's a completely different problem, which is that PHP has no way to > declare APIs as functionally pure, or exception-less. That's something to > be explored, in my opinion, but the lack of it does not warrant dismissin= g > interfaces altogether (your current argument). > You completly ignored 1.: *any* object is serializable. Another hint there isn't any abstraction sitting here: if Serializable was one, it would be like a small wall in wide field. The only way we could make "Serializable2" an abstraction is by fordbidding any object that *does not* impementit to be serializable. That's unrealistic - and uneeded to me. > Serializability is something to be declared: currently, PHP is very much > ill-designed on this particular scope, but that doesn't mean that we shou= ld > make it even worse. > > From this reasoning, I conclude that we really want magic methods here >> because what we need is a *behavior*. We want to hook into the engine to >> benefit from some special features it provides. That's what all magic >> methods are about and hooking into serialize()/unserialize() is not >> different. >> > > Yet more magic methods just add an impressive amount of complexity to the > language (I'm already thinking of the permutations of edge cases that I'm > personally going to have to write). > Please do, I'd be happy to better understand your pov. It's yet another way to define something that would work correctly if an > interface (existing mechanism defined by the language) was used instead. > It would not abstract anything, thus would be just broken syntactic illusional sugar. Magic methods would just provide that, without polluting the semantics >> space. >> > > The newly introduced magic methods pollute the entire **language > semantics**: now you have another edge case in the language, instead of a= n > interface that works in combination with the `serialize()` and > `unserialize()` functions. > "Language semantics" is another thing. I'm talking about "domain semantics". See reasoning above :) I'll also add that the problem being solved is much smaller than the issues > introduced by the > proposed additions. > I promise the contrary: my personal experience is that Serializable does real harm (please work on https://github.com/symfony/symfony/issues/29951 and related issues to get the feeling). Magic methods would solve all this crap. Cheers, Nicolas --0000000000000e9b5905808081e5--