Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53031 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83872 invoked from network); 6 Jun 2011 15:15:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2011 15:15:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=sean@seancoates.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sean@seancoates.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain seancoates.com from 64.15.79.181 cause and error) X-PHP-List-Original-Sender: sean@seancoates.com X-Host-Fingerprint: 64.15.79.181 iconoclast.caedmon.net Received: from [64.15.79.181] ([64.15.79.181:55726] helo=iconoclast.caedmon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/D1-06642-61FECED4 for ; Mon, 06 Jun 2011 11:15:35 -0400 Received: from localhost (localhost [127.0.0.1]) by iconoclast.caedmon.net (Postfix) with ESMTP id 05FF778404F; Mon, 6 Jun 2011 11:16:37 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at iconoclast.caedmon.net Received: from iconoclast.caedmon.net ([127.0.0.1]) by localhost (iconoclast.caedmon.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tsBCq-yqyinM; Mon, 6 Jun 2011 11:16:36 -0400 (EDT) Received: from [10.0.1.13] (cpe-72-227-135-34.nyc.res.rr.com [72.227.135.34]) by iconoclast.caedmon.net (Postfix) with ESMTPSA id DC0DA784043; Mon, 6 Jun 2011 11:16:35 -0400 (EDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=windows-1252 In-Reply-To: Date: Mon, 6 Jun 2011 11:15:29 -0400 Cc: Sanford Whiteman , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <0DA0967D-817B-49FF-B459-4A6B441921C4@seancoates.com> References: <1181529113.20110605190617@cypressintegrated.com> To: dukeofgaming X-Mailer: Apple Mail (2.1084) Subject: Re: [PHP-DEV] Object and Array Literals From: sean@seancoates.com (Sean Coates) > Can you provide an use case and code example of how that would look? Sure. Here's how an ElasticSearch query currently looks in PHP: $esQuery =3D new \StdClass; $esQuery->query =3D new \StdClass; $esQuery->query->term =3D new \StdClass; $esQuery->query->term->name =3D 'beer'; $esQuery->size =3D 1; // OR $esQuery =3D (object)array( "query" =3D> (object)array( "term" =3D> (object)array( "name" =3D> "beer" ) ), "size" =3D> 1 ); =85and here's how it could look with the proposed syntax: "query" : { > "term" : { > "name": "beer" > } > }, > "size" : 1 > }' Even considering the `(object)array(` syntax, it's much easier to work = with an external query (as shown with curl), if we have a (nearly) = JSON-compatible syntax in PHP. Note that I *could* have written the PHP definition of $esQuery with the = proposed syntax and non-JSON compatible syntax (single quotes, for = example), but I chose to write it with double quotes because I knew I = might also want to pass it to curl. Realistically, "beer" would be in a variable (maybe `{"term": {"name": = $term}}`), but replacing just the variables is certainly much easier = than translating the `new \StdClass` syntax. The argument for right-hand-side assignments being allowed in the = proposed syntax (such as in `{'time': time()}`) is still valid because I = expect this syntax will be used both for interoperating with third party = services (as above), but also generally for object and array creation = without a care about third parties. S