Re: RFC: Short syntax for Arrays (redux)
| From: | Andrei Zmievski | Date: | Sat, 04 Jun 2011 04:40:57 +0000 |
| Subject: | Re: RFC: Short syntax for Arrays (redux) | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-52879@lists.php.net to get a copy of this message | ||
On Fri, Jun 3, 2011 at 3:11 PM, David Zülke
<david.zuelke@bitextender.com> wrote:
> It's not FUD.
>
> 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.
>
> David
Of course I know how json_decode() works, David. My question back to
you is, do you know how a parser works? Because there's no reason to
invoke json_decode() on $fancyNewArray, since it would already be an
object, constructed by the Zend parser. The handling of the characters
in the key/value strings is exactly the same as in normal object
property assignments.
-Andrei
P.S. Stop being so patronizing.