var foo = <?=json_encode($my_string)?>;
... (yes, they maybe heared somewhere that JSON is *not* javascript, I
told 'em too).

JSON is a strict subset of JavaScript, and the above scenario is something I also do often.

Since PHP generates web pages, any time I need to generate a JS literal json_encode() is the natural equivalent of var_export(.., true) for PHP literals.

Since it may not match the RFC apparently, I suggest a flag as some other people said:

function json_encode($var, $allowScalar = false) {}

This way we gain best of both worlds without disrupting either specs nor existing workflows.

Regards,
Stan Vassilev

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to