RE: [PHP-DEV] Removing basic types from our JSON parser
| From: | Uwe Schindler | Date: | Sun, 14 Dec 2008 09:40:49 +0000 |
| Subject: | RE: [PHP-DEV] Removing basic types from our JSON parser | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-42252@lists.php.net to get a copy of this message | ||
> <script>
> var foo = <?php echo json_encode($foo)?>;
> </script>
>
> will always work. The only question is what sort of variable foo will
> end up being. The RFC says we have to wrap basic types in an array or
> object, while currently we let the basic types through without the
> wrapper.
He problem her eis: A lot of people use in a way and assume, that a basic
type is serialized as a basic type in JSON/JS. If we change this, it could
break a lot of apps.
And the above is really nice to encode PHP strings to a secure JS variant.
It is hard to do with addslashes etc. So I think, we should not change the
way it works currently.
I think in the docs for json_encode() should be a warning: "JSON officially
only supports Objects and Arrays as outer/top-level/... type for JSON
serializations. So the argument of json_encode must be a PHP object or array
to be fully JSON conformant. If you provide a simple type (string, number,
Boolean), json_encode will generate a valid java script, but some conformant
JSON parser may not be able to read it." How about this?
Uwe