Hacker News new | past | comments | ask | show | jobs | submit login

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 '=>'?


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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: