Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91954 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14663 invoked from network); 25 Mar 2016 20:19:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Mar 2016 20:19:16 -0000 Authentication-Results: pb1.pair.com header.from=scott@paragonie.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=scott@paragonie.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain paragonie.com designates 209.85.214.175 as permitted sender) X-PHP-List-Original-Sender: scott@paragonie.com X-Host-Fingerprint: 209.85.214.175 mail-ob0-f175.google.com Received: from [209.85.214.175] ([209.85.214.175:33039] helo=mail-ob0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/A5-10214-24D95F65 for ; Fri, 25 Mar 2016 15:19:15 -0500 Received: by mail-ob0-f175.google.com with SMTP id xj3so64606206obb.0 for ; Fri, 25 Mar 2016 13:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragonie-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=88tuRY78vcqLL1QtQQBaD3P9BoGNeJeUMOJPGxLxbHc=; b=mNud+ryqaXnVPwfvyzEgtI09LPxRUajeicbpFzNO5VMAlNfpVLx653ufgqZ3j1rTp9 mGwsH+wnEKxIx/SZvC/q3qlvBRUpzaLZban9wArXST0xbe+a0KH6VeyYAn+55IEpCpHf 06JhWGkdMVOAlEjvO7uJ1f3Sn7mCB3tj0wQE47X8strLAX5+m6POLGximIlukkNu5DS/ uVa3aR393MDf+IPH/cOtzv4bNi3GsXmj8YGbLIobMnEp87nh0dClNWzIeFSPcCk/d6NL oOyWnCE/EVexETJ0DOf9kvMxhBihdRW8AgML+Rqlp6QG+me2gAhfW5YcVGxeptwuorh/ qaXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=88tuRY78vcqLL1QtQQBaD3P9BoGNeJeUMOJPGxLxbHc=; b=K6NSWdpbuT3QpacyMmAzieY/kb0aQfm8OBPhYOaBY2cUPtRTIf/cmYVo3ha8xuRBif NfHR1fR0ucLtb2lAV3Cjfn+ifENmbh0aJ0Q6yIx9Lxuke/HxtPe0drTn7uAeUVNEe3RW lXAP8alWjBCyxc4yETEBJA1+q0WOxvrR1DmaiTYnro9CvniTe8Z0yGrntp+0B3V77JmZ PJ/j4vcQHzVl17UGHxxdSyC+rNARm8aUqfVrb0LSJy/dD3h3upemzY1GepHROVvHP7Wo /2o9XjsPWB81Xk91ntCjE5GFhNqbT3VUeBVUCgTE7V2ch5QdrIjS/FFFZvZajzCUlB8f A9tQ== X-Gm-Message-State: AD7BkJJFgy7ps9PARbBIXJctnHmdsW8KIucooyad3Eozrg6jno1cp87BpDBu7Nb9acvUt6HLi7SJVkdImFWfdw== MIME-Version: 1.0 X-Received: by 10.182.96.99 with SMTP id dr3mr7410987obb.79.1458937151739; Fri, 25 Mar 2016 13:19:11 -0700 (PDT) Received: by 10.157.14.42 with HTTP; Fri, 25 Mar 2016 13:19:11 -0700 (PDT) In-Reply-To: References: Date: Fri, 25 Mar 2016 16:19:11 -0400 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary=001a11c2e35eadf224052ee546a8 Subject: Re: [PHP-DEV] Allow empty property names From: scott@paragonie.com (Scott Arciszewski) --001a11c2e35eadf224052ee546a8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Mar 25, 2016 at 1:45 PM, Nikita Popov wrote: > Hi internals, > > Currently we do not allow (*) creating empty property names on objects, > i.e. > > $obj->{''} =3D 42; > > is illegal. While empty property names are unlikely to be useful per se, > they are problematic for deserialization of foreign formats like JSON. To > avoid this issue {"": null} will currently decode to a property named > "_empty_" rather than "". Notably, this means that JSON decode and encode > do not round-trip (as we do not convert _empty_ back to an empty name whi= le > encoding). > > There is no technical reason (that I can see) for keeping this arbitrary > restriction. I believe that the original reason for the restriction was o= ur > use of NUL-prefixed property names for name mangling, combined with the > fact that an empty string at the C level happens to "start" with a NUL > byte. > > A patch to drop the restriction and allow empty property names: > https://github.com/php/php-src/pull/1836 It does not touch the JSON > handling, as there are BC concerns involved there, I leave that to the > ext/json maintainer. > > Any objections to changing this? > > Regards, > Nikita > > (*) There are roundabout ways to create them anyway. > =E2=80=8BCurrently, this succeeds: $x =3D json_decode('{"_empty_": "no", "": "foo"}', true); While this does not: $x =3D json_decode('{"_empty_": "no", "": "foo"}'); =E2=80=8Bhttps://3v4l.org/FJHVV =E2=80=8Bhttps://3v4l.org/15Sfm=E2=80=8B I'm personally 50/50 on it. =E2=80=8BI think allowing an empty property is = kind of weird, but not the weirdest behavior PHP allows. Overall, it might (ironically enough!) make working with JSON _more_ consistent, and probably have other benefits that I can't even imagine at the moment. Scott Arciszewski Chief Development Officer Paragon Initiative Enterprises =E2=80=8B --001a11c2e35eadf224052ee546a8--