Le dimanche 14 décembre 2008 à 00:39 -0800, Rasmus Lerdorf a écrit : > <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.
I believe that for most people it will feel more natural if foo's type is not changed to an object or an array. However I notice with current Firefox (I don't have MSIE, and I'm too lazy to read the whole ECMA Script specs) that an array with only one element is represented by JavaScript the same way. ([ "foo" ]).toString().charAt(1) "foo".toString().charAt(1) document.write([ "foo" ]) document.write("foo") Both works the same in each case. Even alert() will display the value of the first element. IMO it might be possible to wrap values into arrays without breaking too much JS code (bools and other scalars will still not work as expected, and of course an array will not have strings functions) as I think most uses of json_encode() are for strings escaping. Mark -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php