Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52581 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94378 invoked from network); 31 May 2011 21:34:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 May 2011 21:34:33 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.212.173 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.212.173 mail-px0-f173.google.com Received: from [209.85.212.173] ([209.85.212.173:54602] helo=mail-px0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4B/AC-25701-7EE55ED4 for ; Tue, 31 May 2011 17:34:32 -0400 Received: by pxi16 with SMTP id 16so3042132pxi.18 for ; Tue, 31 May 2011 14:34:29 -0700 (PDT) Received: by 10.143.60.15 with SMTP id n15mr1047437wfk.170.1306877669232; Tue, 31 May 2011 14:34:29 -0700 (PDT) Received: from [192.168.200.149] (c-76-126-236-132.hsd1.ca.comcast.net [76.126.236.132]) by mx.google.com with ESMTPS id x8sm239215wfx.7.2011.05.31.14.34.28 (version=SSLv3 cipher=OTHER); Tue, 31 May 2011 14:34:28 -0700 (PDT) Message-ID: <4DE55EE3.9050606@lerdorf.com> Date: Tue, 31 May 2011 14:34:27 -0700 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 MIME-Version: 1.0 To: Stas Malyshev CC: PHP internals References: <4DE5368A.6050603@moonspot.net> <2BFFEAC1-395E-4101-9452-002E63DCFD91@seancoates.com> <4DE55AB7.9050206@lerdorf.com> <4DE55CDA.302@sugarcrm.com> In-Reply-To: <4DE55CDA.302@sugarcrm.com> X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Short syntax for Arrays (redux) From: rasmus@lerdorf.com (Rasmus) On 05/31/2011 02:25 PM, Stas Malyshev wrote: > Hi! > >> Stas, I didn't understand your point about eval() and security. What did >> you mean? > > I meant if PHP has JSON syntax as native, e.g. you can say something like: > > $a = {"a":"b"}; > > Then the temptation would be to write something like: > > // $json_string is {"a":"b"} > $a = eval($json_string); We could perhaps catch that case. I'm not sure that is a reason to reject the idea. People who use eval() on user-supplied data are already lost causes and trying to design for that case is tricky. > Also, with full JSON support it is not entirely clear to me what {"a": > "b"} would mean - is it an array or an object? In JS, it's definitely an > object, but in PHP objects are almost never used to store pure state > without behavior, because we have hashtable arrays, while JS only has > vector arrays. So here we have some unclear point (which does not happen > with [] syntax, since with [] it's obvious we're talking about arrays, > just as in many other languages). Right, this is a trickier issue. In order to handle both associative arrays and objects the PHP notation would need to be along the lines of: [ 1,2,3 ] - Scalar array [ 'a':1, 'b':2 ] - Associative array { 'a':1, 'b':2 } - Stdclass object with properties a and b of course the middle case is not valid json and then things break down a bit. If we are going to support full json and then not be completely compatible, why use the json syntax at all. And not supporting associative arrays in the syntax is not an option. -Rasmus