rfc:objectarrayliterals
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
rfc:objectarrayliterals [2011/06/05 21:34] – [Syntax Examples] dukeofgaming | rfc:objectarrayliterals [2014/04/08 22:49] – Inactive levim | ||
---|---|---|---|
Line 1: | Line 1: | ||
===== RFC: First-Class Object and Array Literals ===== | ===== RFC: First-Class Object and Array Literals ===== | ||
+ | |||
+ | * Version: 1.0.3 | ||
+ | * Date: 2011-06-04 (Updated: 2011-06-06) | ||
+ | * Author: Sean Coates < | ||
+ | * Status: Inactive | ||
==== Introduction ==== | ==== Introduction ==== | ||
Line 18: | Line 23: | ||
This proposal calls for first-class JSON-like object and array literals | This proposal calls for first-class JSON-like object and array literals | ||
(a.k.a. primitives, constructs) in PHP. | (a.k.a. primitives, constructs) in PHP. | ||
+ | |||
+ | This RFC supersedes the existing [[rfc: | ||
Line 36: | Line 43: | ||
Furthermore, | Furthermore, | ||
concerns a declaratative, | concerns a declaratative, | ||
+ | |||
+ | In JSON-proper, | ||
Point of discussion (see below): the key-value separator will be both PHP's | Point of discussion (see below): the key-value separator will be both PHP's | ||
Line 95: | Line 104: | ||
?> | ?> | ||
</ | </ | ||
+ | |||
+ | === Interaction with third-party services that speak JS-literals === | ||
+ | <code php> | ||
+ | <?php | ||
+ | // Here's how an ElasticSearch query currently looks in PHP: | ||
+ | |||
+ | $esQuery = new \StdClass; | ||
+ | $esQuery-> | ||
+ | $esQuery-> | ||
+ | $esQuery-> | ||
+ | $esQuery-> | ||
+ | |||
+ | // OR | ||
+ | |||
+ | $esQuery = (object)array( | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ) | ||
+ | ), | ||
+ | " | ||
+ | ); | ||
+ | |||
+ | // …and here's how it could look with the proposed syntax: | ||
+ | |||
+ | $esQuery = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | " | ||
+ | }; | ||
+ | |||
+ | /* | ||
+ | …and here's how I'd use curl to ensure that the query I'm issuing does in fact work with ElasticSearch: | ||
+ | |||
+ | $ curl http:// | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | " | ||
+ | }' | ||
+ | */ | ||
+ | </ | ||
+ | |||
+ | Even considering the '' | ||
+ | |||
+ | Note that this could have been written with the PHP definition of $esQuery in the proposed yet non-JSON compatible syntax (single quotes, for example), but it was written with double quotes because it is easier to pass off to curl. | ||
+ | |||
+ | Realistically, | ||
+ | |||
+ | The argument for right-hand-side assignments being allowed in the proposed syntax (such as in '' | ||
+ | |||
==== Benefits ==== | ==== Benefits ==== | ||
Line 122: | Line 187: | ||
* JavaScript (with which nearly all modern web apps must interface in some form) supports a very similar syntax. JavaScript (largely) supports a non-strict JSON implementation. The " | * JavaScript (with which nearly all modern web apps must interface in some form) supports a very similar syntax. JavaScript (largely) supports a non-strict JSON implementation. The " | ||
* Python supports a very similar syntax for defining lists and sets (which are somewhat analogous to PHP's arrays (non-associative)), | * Python supports a very similar syntax for defining lists and sets (which are somewhat analogous to PHP's arrays (non-associative)), | ||
- | * Ruby 1.9.1 added [[http:// | + | * Ruby 1.9.1 added [[http:// |
Line 143: | Line 208: | ||
* Performance concerns: encoding/ | * Performance concerns: encoding/ | ||
+ | ==== Patch ==== | ||
+ | * A partial (arrays only, colons only) [[http:// | ||
+ | |||
+ | ==== Discussions ==== | ||
+ | |||
+ | * [[http:// | ||
==== Further Discussion Required ==== | ==== Further Discussion Required ==== |
rfc/objectarrayliterals.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1