Re: json_encode() x-notation

From: Date: Wed, 04 Jul 2018 21:54:53 +0000
Subject: Re: json_encode() x-notation
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-102589@lists.php.net to get a copy of this message
Hi David, David Rodrigues wrote:
​Hello. I saw that JS supports the x-notation (\x40) and u-notation (\u0040), but PHP only supports u-notation. There some reason for that? JSON.parse('"\x40"'); // => @ JSON.parse('"\u0040"'); // => @ While PHP: json_decode('"\\u0040"'); // => @ json_decode('"\\x40"'); // => null (Syntax error) The json.org really don't seems doc the x-notation version, but some pages does: http://www.javascriptkit.com/jsref/escapesequence.shtml The same is valid to json_encode('@'), it will stringify to '\u0040' instead of the most simplified version '\x40'. I don't know if there are some reason for that, but I think that, at least, is reasonable to json_decode() supports that.
Douglas Crockford tried to keep JSON as minimal as possible, so that's probably why JSON doesn't support \x. That it's supported by JS doesn't matter, JSON isn't JS. In JS it is just a synonym for \u so there's not really anything you're missing out on anyway. Thanks. -- Andrea Faulds https://ajf.me/

« previous php.internals (#102589) next »