Hi,

After reading all the debate in the other thread it is still not clear to me
what the real advantages are of adopting JSON syntax for native PHP
types. Doing json_encode to an object and expect the code and output to be
the same seems useless to me, and reading David Zülke's example it seems
more like a pure-unicode issue to me:

----

It is different from writing json_decode('ä\u0123'), because json_decode()
in PHP only accepts UTF-8 encoded input;

Give it a shot:

<?php
$chr = "\xC3\xA4"; // "ä" as UTF-8
var_dump(json_decode('["' . $chr . '\u00e4"]'));
var_dump(json_decode('["' . utf8_decode($chr) . '\u00e4"]'));
?>

That'll produce:

> array(1) {
>   [0]=>
>   string(4) "ää"
> }
> NULL

Understand what the problem is now?

If someone does this in a latin1-encoded file:

<?php $fancyNewArray = {"yay": "ä"}; ?>

Then that is valid as a PHP array (as it's a latin1 "ä", so \xE4), but
cannot be consumed by PHP's json_decode(). And that would be terribly
inconsistent behavior.

-----

It looks more like you want to do json_decode to PHP code hoping that will
somehow fix json_decode... instead of fixing json_decode.

Could someone advocating this please explain with use-cases and concrete &
punctualized examples the advantages of having such JSON approach to PHP.

Regards,

David Vega

Reply via email to