Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87156 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61911 invoked from network); 13 Jul 2015 19:17:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2015 19:17:23 -0000 Authentication-Results: pb1.pair.com header.from=aaron@icicle.io; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=aaron@icicle.io; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain icicle.io designates 199.38.81.6 as permitted sender) X-PHP-List-Original-Sender: aaron@icicle.io X-Host-Fingerprint: 199.38.81.6 mercury.negativeion.net Received: from [199.38.81.6] ([199.38.81.6:58981] helo=mercury.negativeion.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/2E-43998-EBE04A55 for ; Mon, 13 Jul 2015 15:17:19 -0400 Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 956AC27F1206; Mon, 13 Jul 2015 15:17:15 -0400 (EDT) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8Nh6fHEbWK5r; Mon, 13 Jul 2015 15:17:13 -0400 (EDT) Received: from macpro.local (unknown [173.225.158.77]) by mercury.negativeion.net (Postfix) with ESMTPSA id A489327F11EA; Mon, 13 Jul 2015 15:17:13 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) In-Reply-To: Date: Mon, 13 Jul 2015 14:17:12 -0500 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Dean Eigenmann X-Mailer: Apple Mail (2.2098) Subject: Re: [PHP-DEV] JsonSerializable New Interface method Proposal From: aaron@icicle.io (Aaron Piotrowski) > On Jul 13, 2015, at 1:56 PM, Dean Eigenmann = wrote: >=20 > I have updated the RFC with a new section showing the updates >=20 > Sent from my iPhone >=20 >> On 13 Jul 2015, at 20:47, Benjamin Eberlei = wrote: >>=20 >> On Mon, Jul 13, 2015 at 3:22 PM, Dean Eigenmann = >> wrote: >>=20 >>> Ive just opened a new RFC https://wiki.php.net/rfc/jsonserializable = regarding >>> Json to Object unserialization. >>=20 >> The approach with typecasting will not work, because the function >> json_decode doesn't have that information. >>=20 >> Instead something like the JMS Serializer api is probably necessary: = $user >> =3D json_decode($data, 'User'); >>=20 >> I agree with Guilherme that we need a second interface for this, = especially >> because changing the existing one would be a BC break. >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 What are the advantages of the proposed functionality versus writing a = static constructor? Writing $user =3D json_decode_to_class($json, User::class); doesn=E2=80=99= t seem to offer anything over $user =3D User::fromJson($json);. In my = opinion, it seems less obvious what is happening in the former case and = the latter case requires no additional functions or modification to the = engine. Regards, Aaron=