Re: Removing basic types from our JSON parser

From: Date: Sun, 14 Dec 2008 04:19:04 +0000
Subject: Re: Removing basic types from our JSON parser
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-42241@lists.php.net to get a copy of this message
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

« previous php.internals (#42241) next »