Re: json_encode()

From: Date: Tue, 16 Dec 2008 12:29:27 +0000
Subject: Re: json_encode()
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-42289@lists.php.net to get a copy of this message
On 12/16/2008 14:23, Alexey Zakhlestin wrote:
On Tue, Dec 16, 2008 at 3:20 PM, troels knak-nielsen<troelskn@gmail.com> wrote:
On Tue, Dec 16, 2008 at 12:57 PM, Scott MacVicar<scott@macvicar.net> wrote:
For now I'll be leaving it as is and adding a JSON_STRICT_ENCODE parameter to the options flag. So you can use json_encode($var, JSON_STRICT_ENCODE);
I'm really not a fan of named constants to change the semantics of a function like that. Not to mention that it's a pita to type out, so nobody would bother. It also doesn't address the crux of the matter - That the name json_encode is slightly misleading, in that it may or may not emit json. Would it be a problem to introduce a second function (js_encode?) instead? It could work as json_encode does today, and json_encode could then be changed to raise a warning on illegal input. I realise that this means breaking existing scripts, but it's a trivial change, and if it's announced in advance, people should have time to make that sed -r '/json_encode/js_encode/g' to their code base.
sounds like a proper way to me
Me too, but I rather name the function js_escape instead of js_encode.

« previous php.internals (#42289) next »