Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91955 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16622 invoked from network); 25 Mar 2016 20:32:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Mar 2016 20:32:15 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.53 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.215.53 mail-lf0-f53.google.com Received: from [209.85.215.53] ([209.85.215.53:33614] helo=mail-lf0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/06-10214-C40A5F65 for ; Fri, 25 Mar 2016 15:32:12 -0500 Received: by mail-lf0-f53.google.com with SMTP id f67so6366922lfb.0 for ; Fri, 25 Mar 2016 13:32:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=riejIYsWAzfCJXhV3VYFJ32aaE2yUhoP4+vtdjJ+nXw=; b=tfPIS9gSAXccX6Bvac1dnix3QAJrLYcuXOiBB4jJPRUzcXucQdOBRniulB4p1+xhkH YwQ4wp1f0XKLad+Nkb/QFBxQ/wcLXuuFHcr59GRJbd1yeJnAXalz/FhZTfSGRbK8Xoc2 tCToWLP7gzqdSrXBeefdXF4NV0k39I4EorUy4hJMOJrPMAhluhXKeLDo2EEZBfmcKW+V jnh/5o6L6EwvLi20pborrnwKLzDYG2pyMpuKKLRQvWlfEHP5A3kKhP1aG3/BEgYWsiCn l77G76UYub9MWYLbgTHRt4CL5r2FOsM5Gpwa02bFy3NzLUmun77g0oW6oqAlD2uja2sI YoOQ== 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:from:date :message-id:subject:to:cc; bh=riejIYsWAzfCJXhV3VYFJ32aaE2yUhoP4+vtdjJ+nXw=; b=m7lTmfNnSOmbAns6h0l4f6CHF2qM5QfcHXolu2DS/WSpSOWnQzdfEvE7d2ExG0WT2v nVcPRHOcWcExEDrg0IiJMnI9EbrUK591domGZZzjmeOH2C2m0JTqawTTwmvhhv0CVcCb U+Yq0IySgS4Dl4Nq07OwKkg/dBZqT3nVa9p+1Wt1P4INN4rgQRXLToBz57BVQqZBMFLc +aQmAYZpOYdayPl9kD1B1TSGzodf00hW2ZfDzy67qIrorMPkiagpEuMpJ6qPBu0ZsWt+ Mr2d/gZy7+A3ZOYK+UGDWw2vfni/33wZy6QKbFkw7w49eXI5iv6QeCXLigRLLy2iubIw /rbA== X-Gm-Message-State: AD7BkJIwHy6Uix+tU4T3HKHYkr1AxfsiQ6019cHg0dQPV2hqIPBXCIKC8AtshVduxd+nlrZli4KzFRNHIQVVgw== X-Received: by 10.25.27.12 with SMTP id b12mr6304182lfb.97.1458937929781; Fri, 25 Mar 2016 13:32:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.225.38 with HTTP; Fri, 25 Mar 2016 13:31:50 -0700 (PDT) In-Reply-To: References: Date: Fri, 25 Mar 2016 21:31:50 +0100 Message-ID: To: Scott Arciszewski Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=001a114013240dd5eb052ee57515 Subject: Re: [PHP-DEV] Allow empty property names From: ocramius@gmail.com (Marco Pivetta) --001a114013240dd5eb052ee57515 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 25 March 2016 at 21:19, Scott Arciszewski wrote: > 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 enco= de > > do not round-trip (as we do not convert _empty_ back to an empty name > while > > encoding). > > > > There is no technical reason (that I can see) for keeping this arbitrar= y > > restriction. I believe that the original reason for the restriction was > our > > 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 i= s kind of > weird, but not the weirdest behavior PHP allows. Overall, it might > (ironically enough!) make working with JSON _more_ consistent, and probab= ly > have other benefits that I can't even imagine at the moment. > Note that also that these ones won't work at the moment: var_dump((object) ['' =3D> 'foo']); var_dump((object) ["\0*\0" =3D> 'foo']); var_dump((object) ["\0Foo\0" =3D> 'foo']); Seems to work consistently on HHVM though: https://3v4l.org/7MO7E Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --001a114013240dd5eb052ee57515--