Re:PHP 5.5.0 Alpha 6 - Released
by Jeremy1026 on Friday March 08, 2013 @06:35PM
(#5346485)
JSON, JavaScript Object Notation. How does it make sense to write PHP in Javascript syntax, when PHP has its own defined syntax?
Because 1) PHP syntax for object literals is non-existent 2) JSON is used in many more places than just Javascript and 3) the syntax of JSON makes sense; it's compact, human readable and easy to write. I'm not suggesting copying it 1:1 verbatim, but something close to JSON would definitely be an improvement. See for example how MongoDB uses a JSON-like syntax to great effect.
If for no other reason than ':' is easier to type than '=>'?
Re:PHP 5.5.0 Alpha 6 - Released
by BystanderX on Friday March 08, 2013 @07:29PM
(#5346694)
Hell will surely descend upon me, but I'd vote for having it be syntactic sugar for => in general.
You can already use the js-style shorthand inside of Twig templates, and I've been caught absentmindedly forgetting to switch to the 'proper' way for raw php now and then. And I would like to never need to even touch the shift key when having to write out an array or an object but even JSON won't let you do that. It's a step in the right direction, though.
Telling people to use arrays and be done with it is the equivalent of implement a strpos function that may only accept a string that's 5 characters long — yes, theoretically you can work with that splitting your strings, but that's time consuming and a inconsistent behaviour (why would 10 character long strings be less of a citizen than 5 char long ones?)