Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103858 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11936 invoked from network); 28 Jan 2019 11:19:13 -0000 Received: from unknown (HELO mail-it1-f193.google.com) (209.85.166.193) by pb1.pair.com with SMTP; 28 Jan 2019 11:19:13 -0000 Received: by mail-it1-f193.google.com with SMTP id z7so19256599iti.0 for ; Sun, 27 Jan 2019 23:58:17 -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=Ixjk5n8ToBHdSdmEggV8UPbnxBOhoYaQfw6/Ke0phOs=; b=RrKCdtqnymRFI9obotHKT62ZaHio38NOnF67tQfOO/Avs5FGX/E7nMiI6DJFDkXPH9 TFSsO6IC2SFBDNSGfbpCGVVVqJvwr58f9A6khJPZAA1q+R2Ja+Ke1b4lsT96sa4Hwgsj 67+4BkJ0enbXosrqQxJWyzHtvK+/Wf9XVZHc3pqqeHx27tswSrFA8qfFKA0WfiJco7/l khBB56Gcl1HA0GRaTqef0dBozc/WwAmP8opKFuRl6dLL6dQdgIr+A+vxiI//7iI2xVP1 OKBGUJTncj3H7UveZS9NvPKjk1b9/9Axlsxh3uHarsG7slDCgnq0vmrkXMgpORJd4alR gydQ== 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=Ixjk5n8ToBHdSdmEggV8UPbnxBOhoYaQfw6/Ke0phOs=; b=hTX1HYZtYZYvuyc2C9XbeEPZ5VjjaSP0yy/PtBhJjj3yrsyz/3W51wb3QCknyKzZV9 QcgpVyUpY9GSEcZimFTEgp2NwjcqLSIdYR6vK/KC/tg4bJL4EBNX4eUL9pEHueQ0tNo/ l6kvOOO5aFD42xaOnd424z+xsyh2spUl08izHcv48axCWlLoSIHOCuM+sVpSVj/jSEvn 7mzlbme8Fh7dSPzMVKSKOp5WF5xlnxzexFKf2JkKFGoQKcK/xEAqOOgdF/k7h9tNeUd3 pNWd6LCZATSbfiTaXjcqXVEgxUc9B5Ks62g8vPD0UwDESDj+bzNkvN0dT47DjEMH9jNc Yl9Q== X-Gm-Message-State: AJcUukf5vzdyyQKnmVclUs2PnrpaoEaRPiHxrYTL3jq9j+JOxYMZtTDs nQb2Ev802IgHWbKCkwV3KpwPWSxS2lvYGiCoYGs= X-Google-Smtp-Source: ALg8bN60Woy1BANyGrenCSh3ghT2o9JINfouilgmdih9VngTs0YHkcrkMoboA9e5ymFTdUHH/N42pDd4qQb8+aECUmQ= X-Received: by 2002:a24:d441:: with SMTP id x62mr9463075itg.141.1548662297086; Sun, 27 Jan 2019 23:58:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 28 Jan 2019 08:58:05 +0100 Message-ID: To: Nicolas Grekas Cc: Sebastian Bergmann , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000001850b70580800aad" Subject: Re: [PHP-DEV] [RFC] New custom object serialization mechanism From: ocramius@gmail.com (Marco Pivetta) --0000000000001850b70580800aad Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Jan 27, 2019 at 5:37 PM Nicolas Grekas 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 - something that an API tpoa 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 perfectly valid use-case scenario. > 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 serializable > thing". That's actually a very correct thing to do: by declaring that something is `Serializable`, you are expressing your intent to anybody inspecting the structure of the object. > 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 dismissing interfaces altogether (your current argument). Serializability is something to be declared: currently, PHP is very much ill-designed on this particular scope, but that doesn't mean that we should 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). It's yet another way to define something that would work correctly if an interface (existing mechanism defined by the language) was used instead. 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 an interface that works in combination with the `serialize()` and `unserialize()` functions. I'll also add that the problem being solved is much smaller than the issues introduced by the proposed additions. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --0000000000001850b70580800aad--