Re: [PHP-DEV] json_encode() and Generators / RFC Karma

2024-09-02 Thread Philip Hofstetter
Hi, On Aug 30, 2024 at 16:47:43, Claude Pache wrote: > > Note that the issue is not limited to Generators. For instance a Closure > object is also json-encodable but not serialisable. > > IMO, every internal class (not just Generator) that is marked as > non-serialisable, should also be non-js

Re: [PHP-DEV] json_encode() and Generators / RFC Karma

2024-08-30 Thread Claude Pache
> Le 30 août 2024 à 09:36, Philip Hofstetter a > écrit : > > Hello, > > In the aftermath of an internal refactoring of an internal code-base to turn > something eager into something more lazy using Generators, it occurred to me > that while PHP refuses to serialize() a Generator, accidenta

Re: [PHP-DEV] json_encode() and Generators / RFC Karma

2024-08-30 Thread Ilija Tovilo
On Fri, Aug 30, 2024 at 12:19 PM Philip Hofstetter wrote: > > Username is pilif RFC karma was granted. Good luck with the RFC!

Re: [PHP-DEV] json_encode() and Generators / RFC Karma

2024-08-30 Thread Philip Hofstetter
Hi John, On Aug 30, 2024 at 09:42:05, John Coggeshall wrote: > This seems entirely reasonable and I would welcome an RFC for it (unless > someone has a better idea as to how to handle this case). > > The other options I considered were to either materialize the Generator, but given that they c

Re: [PHP-DEV] json_encode() and Generators / RFC Karma

2024-08-30 Thread Philip Hofstetter
Hi Ilija, On Aug 30, 2024 at 09:49:14, Ilija Tovilo wrote: > > To grant you RFC karma, I need to know your wiki.php.net username. > Username is pilif Thank you Philip Hofstetter

Re: [PHP-DEV] json_encode() and Generators / RFC Karma

2024-08-30 Thread Ilija Tovilo
Hi Philip On Fri, Aug 30, 2024 at 9:37 AM Philip Hofstetter wrote: > > If you think this is a worthwhile thing to do an RFC for, I would kindly ask > for somebody to grant me RFC karma, so I can start working on one. To grant you RFC karma, I need to know your wiki.php.net username. Ilija

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Jordi Boggiano
On 03/06/2021 18:03, Timon de Groot wrote: On 3-6-2021 17:53, Ayesh Karunaratne wrote: Hi Timon, Thank you for this RFC. I think the `string|int $indent` approach is great 🚀! Reading the PR, it looks like `$indent=0` is essentially turning off pretty-print, which I think is intuitive. Basical

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Timon de Groot
On 3-6-2021 17:53, Ayesh Karunaratne wrote: Hi Timon, Thank you for this RFC. I think the `string|int $indent` approach is great 🚀! Reading the PR, it looks like `$indent=0` is essentially turning off pretty-print, which I think is intuitive. Basically, yes. With `$indent=0`, no indentation will

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Ayesh Karunaratne
Hi Timon, Thank you for this RFC. I think the `string|int $indent` approach is great 🚀! Reading the PR, it looks like `$indent=0` is essentially turning off pretty-print, which I think is intuitive. Do you plan to add any sort of validation on negative integers? Perhaps throw a `\ValueError` exce

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Timon de Groot
On 3-6-2021 16:15, G. P. B. wrote: That's incorrect, as of PHP 8.0 Fast ZPP has a way to deal with the most common union types, including int|string. Best regards, George P. Banyard I found that STR_OR_LONG works fine, thanks for acknowledging! -- Kind regards, Timon de Groot -- PHP Inter

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread G. P. B.
On Thu, 3 Jun 2021 at 11:49, Timon de Groot wrote: > On 3-6-2021 10:00, Jordi Boggiano wrote: > > I agree, but I'd make it accept a string|int much like JSON.stringify > > does, because that way you let people pass in tabs too, or "🚀" if > > that's how you want your JSON indented.. > > I like the

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Guilliam Xavier
Hello, I have seen a similar discussion for var_export(), and the answer was basically "use a regex". E.g.: $json = preg_replace_callback( '/^(?: {4})+/m', fn ($m) => str_repeat($indent, strlen($m[0]) / 4), json_encode($data, JSON_PRETTY_PRINT) ); That said, I wou

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Timon de Groot
On 3-6-2021 10:00, Jordi Boggiano wrote: I agree, but I'd make it accept a string|int much like JSON.stringify does, because that way you let people pass in tabs too, or "🚀" if that's how you want your JSON indented.. I like the idea of accepting string|int. Accepting string|int means a zval

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Timon de Groot
So if you do go ahead and make an RFC for this, I think my preference would be as a new parameter on json_encode accepting a positive integer. Thank your for your input, I'll start working on an RFC to introduce a new parameter for json_encode. -- PHP Internals - PHP Runtime Development Ma

Re: [PHP-DEV] json_encode indent parameter

2021-06-03 Thread Jordi Boggiano
On 03/06/2021 02:45, David Gebler wrote: I would say though (a) is true enough but doesn't necessarily cover all use cases, adds more magic constants and doesn't provide equivalence to the JSON libraries of other common languages which permit for custom values, while (b) is less of an issue with

Re: [PHP-DEV] json_encode indent parameter

2021-06-02 Thread David Gebler
On Wed, 2 Jun 2021, 23:03 Timon de Groot, wrote: > It's not possible to tell json_encode what indentation level should be > used when using > the JSON_PRETTY_PRINT option (2, 4, 8, etc). When generating JSON files > which can be > used/read/edited by users, indentation starts to become a relevant

Re: [PHP-DEV] json_encode() x-notation

2018-07-04 Thread David Rodrigues
Em qua, 4 de jul de 2018 19:01, Nikita Popov escreveu: > On Fri, Jun 29, 2018 at 8:51 PM, 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"'); // =>

Re: [PHP-DEV] json_encode() x-notation

2018-07-04 Thread Nikita Popov
On Fri, Jun 29, 2018 at 8:51 PM, 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"'); // => @ > No it doesn't. JSON.parse(

Re: [PHP-DEV] json_encode() x-notation

2018-06-29 Thread Sara Golemon
On Fri, Jun 29, 2018 at 1:51 PM, 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? > The TL;DR version AIUI, is that JSON strings are Unicode strings, so any byte sequence in a JSON

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-31 Thread Andrea Faulds
Jakub Zelenka wrote: On Sat, Jul 29, 2017 at 7:10 PM, Niklas Keller wrote: Andrea Faulds schrieb am Sa., 29. Juli 2017, 18:55: Hi Craig, Craig Duncan wrote: On 29 July 2017 at 15:16, Andrea Faulds wrote: Could we not simply make it a flag? e.g. $bar = json_encode($foo, JSON_THROW_

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-30 Thread Jakub Zelenka
On Sat, Jul 29, 2017 at 7:10 PM, Niklas Keller wrote: > Andrea Faulds schrieb am Sa., 29. Juli 2017, 18:55: > > > Hi Craig, > > > > Craig Duncan wrote: > > > On 29 July 2017 at 15:16, Andrea Faulds wrote: > > > > > >> Could we not simply make it a flag? e.g. > > >> > > >> $bar = json_encode

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-29 Thread Niklas Keller
Andrea Faulds schrieb am Sa., 29. Juli 2017, 18:55: > Hi Craig, > > Craig Duncan wrote: > > On 29 July 2017 at 15:16, Andrea Faulds wrote: > > > >> Could we not simply make it a flag? e.g. > >> > >> $bar = json_encode($foo, JSON_THROW_EXCEPTIONS); > >> $baz = json_decode($bar, false, 512

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-29 Thread Andrea Faulds
Hi Craig, Craig Duncan wrote: On 29 July 2017 at 15:16, Andrea Faulds wrote: Could we not simply make it a flag? e.g. $bar = json_encode($foo, JSON_THROW_EXCEPTIONS); $baz = json_decode($bar, false, 512, JSON_THROW_EXCEPTIONS); That wouldn't break backwards-compatibility, but would

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-29 Thread Craig Duncan
On 29 July 2017 at 15:16, Andrea Faulds wrote: > Could we not simply make it a flag? e.g. > > $bar = json_encode($foo, JSON_THROW_EXCEPTIONS); > $baz = json_decode($bar, false, 512, JSON_THROW_EXCEPTIONS); > > That wouldn't break backwards-compatibility, but would still provide the > desi

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-29 Thread Andrea Faulds
Hi everyone, Andrea Faulds wrote: Craig Duncan wrote: On 27 July 2017 at 16:57, Niklas Keller wrote: It should rather just throw exceptions. Warnings do not really allow error handling, they just allow error reporting. Agreed, but I can't see Exceptions passing the vote. Warnings can be s

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-29 Thread Andrea Faulds
Hi Duncan, Craig Duncan wrote: On 27 July 2017 at 16:57, Niklas Keller wrote: It should rather just throw exceptions. Warnings do not really allow error handling, they just allow error reporting. Agreed, but I can't see Exceptions passing the vote. Warnings can be silenced by those that do

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-28 Thread Thomas Hruska
On 7/28/2017 3:03 AM, Ryan Jentzsch wrote: I can't count how many times I've been bitten by this. From the infamous fractal blog: "Parts of PHP are practically designed to produce buggy code. json_decode returns null for invalid input, even though null is also a perfectly valid object for JSON t

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-28 Thread Ryan Jentzsch
I can't count how many times I've been bitten by this. From the infamous fractal blog: "Parts of PHP are practically designed to produce buggy code. json_decode returns null for invalid input, even though null is also a perfectly valid object for JSON to decode to—this function is completely unrel

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-28 Thread Niklas Keller
2017-07-28 8:56 GMT+02:00 Giovanni Giacobbi : > On 27 July 2017 at 18:00, Craig Duncan wrote: > >> On 27 July 2017 at 16:57, Niklas Keller wrote: >> >> > It should rather just throw exceptions. Warnings do not really allow >> error >> > handling, they just allow error reporting. >> > >> > >> Agr

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-28 Thread Giovanni Giacobbi
On 27 July 2017 at 18:00, Craig Duncan wrote: > On 27 July 2017 at 16:57, Niklas Keller wrote: > > > It should rather just throw exceptions. Warnings do not really allow > error > > handling, they just allow error reporting. > > > > > Agreed, but I can't see Exceptions passing the vote. Warnings

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-27 Thread Craig Duncan
On 27 July 2017 at 16:57, Niklas Keller wrote: > It should rather just throw exceptions. Warnings do not really allow error > handling, they just allow error reporting. > > Agreed, but I can't see Exceptions passing the vote. Warnings can be silenced by those that don't care and converted to Exce

Re: [PHP-DEV] json_encode() / json_decode() warnings

2017-07-27 Thread Niklas Keller
2017-07-27 17:41 GMT+02:00 Craig Duncan : > Hi internals, > > When using `json_encode()` and `json_decode()` it is required that you > manually check for errors after every call, eg: > > ```php > $data = json_decode("false"); > if (json_last_error() !== JSON_ERROR_NONE) { > throw new Unexpecte

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-28 Thread Nikita Popov
On Wed, Jun 27, 2012 at 2:19 PM, Nikita Popov wrote: > I looked at a few other error functions (of which we by the way we > have *loads*, which is a bad sign) and indeed it seems that they all > use a separate function to get the error message. Most use a > xyz_errno() + xyz_error() pair. > > So i

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-27 Thread Nikita Popov
On Wed, Jun 27, 2012 at 1:40 PM, Pierre Joye wrote: > hi, > > On Wed, Jun 27, 2012 at 1:30 PM, Nikita Popov > wrote: > >>> Why not in the spirit of others have a new function json_last_error_msg() or >>> something similar? >> >> I implemented it with json_last_error(true) returning just a string

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-27 Thread Pierre Joye
hi, On Wed, Jun 27, 2012 at 1:30 PM, Nikita Popov wrote: >> Why not in the spirit of others have a new function json_last_error_msg() or >> something similar? > > I implemented it with json_last_error(true) returning just a string, > not an array. You can get the array using array(json_last_erro

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-27 Thread Nikita Popov
On Wed, Jun 27, 2012 at 1:27 PM, Benjamin Eberlei wrote: > > On Wed, Jun 27, 2012 at 1:41 AM, Stas Malyshev > wrote: >> >> Hi! >> >> > Makes sense to me. So should I do this? Remove warnings + add string >> > parameter for json_last_error? > > > I think its weird that the parameter is called $err

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-27 Thread Benjamin Eberlei
On Wed, Jun 27, 2012 at 1:41 AM, Stas Malyshev wrote: > Hi! > > > Makes sense to me. So should I do this? Remove warnings + add string > > parameter for json_last_error? > I think its weird that the parameter is called $error_string and setting it to true means returning an array. Why not in the

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-26 Thread Stas Malyshev
Hi! > Makes sense to me. So should I do this? Remove warnings + add string > parameter for json_last_error? Looks fine. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, vi

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-26 Thread Nikita Popov
On Sun, Jun 24, 2012 at 5:39 PM, Rasmus Lerdorf wrote: > So how about: > > mixed json_last_error ( [bool $error_string = false] ) > > Returns the last error (if any) occurred during the last JSON > encoding/decoding. By default an integer constant from the table below > is returned. If $error_stri

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-24 Thread Rasmus Lerdorf
On 06/24/2012 05:12 AM, Nikita Popov wrote: > The main problem with not throwing a warning is that it makes > debugging the error quite hard. json_last_error() only gives you an > error code. So you have to use some script like the one used as an > example in php.net/json_last_error to figure out w

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-24 Thread Daniel Convissor
Hola: On Sat, Jun 23, 2012 at 06:03:34PM -0700, Rasmus Lerdorf wrote: > And yes, I don't think a warning from json_encode() is useful because to > properly avoid it you would need an iconv() call before calling it and > that is pure overhead. Short of that your only recourse is to use @ and > that

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-24 Thread Nikita Popov
On Sun, Jun 24, 2012 at 12:50 AM, Gustavo Lopes wrote: > If json_encode() is not supposed to receive badly encoded data, then it's > the application writer's responsibility to make sure that the data is > correctly encoded. If, on the other hand, you think that's actually not a > error on the part

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Rasmus Lerdorf
On 06/23/2012 04:06 PM, Stas Malyshev wrote: > Hi! > >> Maybe it is simply time to rethink the error handling. > > This is true, current error handling has many deficiencies and is also > very expensive even when the errors are muted (we still produce the > whole error string, etc. even if we nev

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Stas Malyshev
Hi! > Maybe it is simply time to rethink the error handling. This is true, current error handling has many deficiencies and is also very expensive even when the errors are muted (we still produce the whole error string, etc. even if we never display it). Unfortunately, BC concerns prevailed last

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Johannes Schlüter
On Sun, 2012-06-24 at 00:24 +0200, Nikita Popov wrote: > Yes, I feel like we must discuss this a thousand times anew. There > clearly is no consensus about it. Just look at the responses in this > thread and in other discussions relating this issue. When people read > "throws a warning, but only if

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Gustavo Lopes
On Sat, 23 Jun 2012 21:53:01 +0200, Stas Malyshev wrote: Hi! The warning for invalid UTF-8 stays intact and is thrown also with display_errors = On. If this behavior is undesired this can be remedied later. Must we discuss it 1000 times anew? There was a reason why it didn't throw warning

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Nikita Popov
On Sat, Jun 23, 2012 at 9:53 PM, Stas Malyshev wrote: > Hi! > >> The warning for invalid UTF-8 stays intact and is thrown also with >> display_errors = On. If this behavior is undesired this can be remedied >> later. > > Must we discuss it 1000 times anew? There was a reason why it didn't > throw

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Ferenc Kovacs
On Sat, Jun 23, 2012 at 9:53 PM, Stas Malyshev wrote: > Hi! > > > The warning for invalid UTF-8 stays intact and is thrown also with > > display_errors = On. If this behavior is undesired this can be remedied > > later. > > Must we discuss it 1000 times anew? There was a reason why it didn't > thr

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Stas Malyshev
Hi! > The warning for invalid UTF-8 stays intact and is thrown also with > display_errors = On. If this behavior is undesired this can be remedied > later. Must we discuss it 1000 times anew? There was a reason why it didn't throw warning when display_errors is on. The reason is that it is very e

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Nikita Popov
I applied a few changes in https://github.com/php/php-src/commit/84fe2cc890e49f40bac7c3ba74b3cfc6dc4cef2f and https://github.com/php/php-src/commit/36fa17a5fae84ab332366a202f0a709279a2466a. >From the commit message: < json_encode() now returns bool(false) for all possible errors, throws the r

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-23 Thread Sherif Ramadan
> > The problem with a warning here is that there is usually no way to > prevent it short of using @ or preceding all calls to htmlspecialchars() > with an iconv() call. A bad guy can simply send invalid UTF-8 bytes to a > web app and look for that warning to get a really good idea about the > serv

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Pierre Joye
hi Rasmus, On Thu, Jun 21, 2012 at 5:33 PM, Rasmus Lerdorf wrote: > The problem with a warning here is that there is usually no way to > prevent it short of using @ or preceding all calls to htmlspecialchars() > with an iconv() call. A bad guy can simply send invalid UTF-8 bytes to a > web app a

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Pierre Joye
On Thu, Jun 21, 2012 at 4:12 PM, Daniel Convissor wrote: > Hi Nikita: > >> PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 >> string is encountered: >>  * A warning is thrown, but only if display_errors=off > > So the warning is put into the error log?  But only if display_e

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Rasmus Lerdorf
On 06/21/2012 07:25 AM, Nikita Popov wrote: > On Thu, Jun 21, 2012 at 4:12 PM, Daniel Convissor > wrote: >> Hi Nikita: >> >>> PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 >>> string is encountered: >>> * A warning is thrown, but only if display_errors=off >> >> So the wa

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Laruence
On Thu, Jun 21, 2012 at 10:25 PM, Nikita Popov wrote: > On Thu, Jun 21, 2012 at 4:12 PM, Daniel Convissor > wrote: >> Hi Nikita: >> >>> PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 >>> string is encountered: >>>  * A warning is thrown, but only if display_errors=off >> >

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Nikita Popov
On Thu, Jun 21, 2012 at 4:12 PM, Daniel Convissor wrote: > Hi Nikita: > >> PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 >> string is encountered: >>  * A warning is thrown, but only if display_errors=off > > So the warning is put into the error log?  But only if display_e

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Daniel Convissor
Hi Nikita: > PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 > string is encountered: > * A warning is thrown, but only if display_errors=off So the warning is put into the error log? But only if display_errors is off? And if display_errors is on, no warning is produced?

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Pierre Joye
hi, On Thu, Jun 21, 2012 at 11:21 AM, Nikita Popov wrote: >> 5.3 should be brought in line with 5.4. > So you think that the corrected code should be backed out from PHP 5.3 > and the incorrect 5.4/master behavior be restored? For the warning yes. For the rest, it should imo return false as wel

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-21 Thread Nikita Popov
On Thu, Jun 21, 2012 at 8:47 AM, Pierre Joye wrote: >> The reason for this situation is that a patch was applied for all >> branches, and then reverted, because Stas didn't consider the change >> towards always throwing a warning (even with display_errors=on) >> appropriate without further discuss

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-20 Thread Laruence
On Thu, Jun 21, 2012 at 2:47 PM, Pierre Joye wrote: > hi, > > On Thu, Jun 21, 2012 at 12:21 AM, Nikita Popov > wrote: > >> We currently have a big mess concerning the behavior of json_encode() >> with incorrectly encoded UTF-8 strings. >> >> To summarize the situation: >> >> PHP <= 5.3.13, PHP 5.

Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings

2012-06-20 Thread Pierre Joye
hi, On Thu, Jun 21, 2012 at 12:21 AM, Nikita Popov wrote: > We currently have a big mess concerning the behavior of json_encode() > with incorrectly encoded UTF-8 strings. > > To summarize the situation: > > PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 > string is encou

Re: [PHP-DEV] json_encode() and non-UTF8 strings

2012-04-03 Thread Laruence
On Tue, Apr 3, 2012 at 9:46 AM, Rasmus Lerdorf wrote: > On 04/02/2012 06:35 PM, Charlie Somerville wrote: >> Hi internals, >> >> I've created a pull request (https://github.com/php/php-src/pull/33) that >> changes json_encode to fall back to ASCII for strings that are not valid >> UTF-8. >> >> I

Re: [PHP-DEV] json_encode() and non-UTF8 strings

2012-04-02 Thread Adam Harvey
On 3 April 2012 09:46, Rasmus Lerdorf wrote: > On 04/02/2012 06:35 PM, Charlie Somerville wrote: >> I've created a pull request (https://github.com/php/php-src/pull/33) that >> changes json_encode to fall back to ASCII for strings that are not valid >> UTF-8. >> >> I ran into an issue in a produ

Re: [PHP-DEV] json_encode() and non-UTF8 strings

2012-04-02 Thread Rasmus Lerdorf
On 04/02/2012 06:35 PM, Charlie Somerville wrote: > Hi internals, > > I've created a pull request (https://github.com/php/php-src/pull/33) that > changes json_encode to fall back to ASCII for strings that are not valid > UTF-8. > > I ran into an issue in a production application involving PayP

Re: [PHP-DEV] json_encode()

2008-12-17 Thread Scott MacVicar
Richard Quadling wrote: > 2008/12/16 Robin Burchell : >> Settings which change behaviour like that aren't really all that fun >> for third party/portable applications developers, e.g. forum software >> and the likes. magic_quotes_gpc and others are good examples of this. >> >> Going back to Rasmus'

Re: [PHP-DEV] json_encode()

2008-12-17 Thread Alexey Zakhlestin
On Wed, Dec 17, 2008 at 1:05 PM, Richard Quadling wrote: > Considering json_encode() COULD encode non JSON compliant data, should > json_decode() also decode non JSON compliant data? it should decode as much as it can without any warnings (as long, as there's no ambiguity) -- Alexey Zakhlestin

Re: [PHP-DEV] json_encode()

2008-12-17 Thread Richard Quadling
2008/12/16 Robin Burchell : > Settings which change behaviour like that aren't really all that fun > for third party/portable applications developers, e.g. forum software > and the likes. magic_quotes_gpc and others are good examples of this. > > Going back to Rasmus' mail based on his discussion w

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Ilia Alshanetsky
The proposed solution (basic types flag) is probably the lesser evil, but I still feel were are taking things to far and current operation is correct. On 16-Dec-08, at 6:57 AM, Scott MacVicar wrote: Richard Quadling wrote: 2008/12/15 mike : On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Stan Vassilev | FM
1. Document the fact that if you want to strictly conform to the JSON spec and be sure your json_encode output will work in various JSON parsers, you have to pass it a PHP array or object. +1 Regards, Stan Vassilev -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe,

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Pierre Joye
On Mon, Dec 15, 2008 at 6:50 PM, Rasmus Lerdorf wrote: > Ok, so as promised I ran some of the options we have that came up last > week by Douglas Crockford. > > 1. Document the fact that if you want to strictly conform to the JSON > spec and be sure your json_encode output will work in various J

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Robin Burchell
Settings which change behaviour like that aren't really all that fun for third party/portable applications developers, e.g. forum software and the likes. magic_quotes_gpc and others are good examples of this. Going back to Rasmus' mail based on his discussion with Douglas, I think that option #1 (

Re: [PHP-DEV] json_encode()

2008-12-16 Thread troels knak-nielsen
On Tue, Dec 16, 2008 at 3:06 PM, Richard Quadling wrote: > Would it be at all possible to have an ini setting json.strict_encode = On > > So, my code doesn't change, but I can activate it globally. > Essentially I don't want to shoot myself. I don't want to take the > safety off. I think we have

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Richard Quadling
2008/12/16 Scott MacVicar : > Richard Quadling wrote: >> 2008/12/15 mike : >>> On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf wrote: >>> 1. Document the fact that if you want to strictly conform to the JSON spec and be sure your json_encode output will work in various JSON pars

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Ionut Gabriel Stan
On 12/16/2008 14:23, Alexey Zakhlestin wrote: On Tue, Dec 16, 2008 at 3:20 PM, troels knak-nielsen wrote: On Tue, Dec 16, 2008 at 12:57 PM, Scott MacVicar wrote: For now I'll be leaving it as is and adding a JSON_STRICT_ENCODE parameter to the options flag. So you can use json_encode($var,

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Alexey Zakhlestin
On Tue, Dec 16, 2008 at 3:20 PM, troels knak-nielsen wrote: > On Tue, Dec 16, 2008 at 12:57 PM, Scott MacVicar wrote: >> For now I'll be leaving it as is and adding a JSON_STRICT_ENCODE >> parameter to the options flag. So you can use >> >> json_encode($var, JSON_STRICT_ENCODE); >> > > I'm really

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Scott MacVicar
troels knak-nielsen wrote: > On Tue, Dec 16, 2008 at 12:57 PM, Scott MacVicar wrote: >> For now I'll be leaving it as is and adding a JSON_STRICT_ENCODE >> parameter to the options flag. So you can use >> >> json_encode($var, JSON_STRICT_ENCODE); >> > > I'm really not a fan of named constants to

Re: [PHP-DEV] json_encode()

2008-12-16 Thread troels knak-nielsen
On Tue, Dec 16, 2008 at 12:57 PM, Scott MacVicar wrote: > For now I'll be leaving it as is and adding a JSON_STRICT_ENCODE > parameter to the options flag. So you can use > > json_encode($var, JSON_STRICT_ENCODE); > I'm really not a fan of named constants to change the semantics of a function lik

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Scott MacVicar
Richard Quadling wrote: > 2008/12/15 mike : >> On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf wrote: >> >>> 1. Document the fact that if you want to strictly conform to the JSON >>> spec and be sure your json_encode output will work in various JSON >>> parsers, you have to pass it a PHP array

Re: [PHP-DEV] json_encode()

2008-12-16 Thread Richard Quadling
2008/12/15 mike : > On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf wrote: > >> 1. Document the fact that if you want to strictly conform to the JSON >> spec and be sure your json_encode output will work in various JSON >> parsers, you have to pass it a PHP array or object. > > Instead of json

Re: [PHP-DEV] json_encode()

2008-12-15 Thread Lars Strojny
Hi Rasmus, Am Montag, den 15.12.2008, 14:17 -0800 schrieb Rasmus Lerdorf: [...] > There has to be a way to do a basic type without any sort of error or > warning. E_STRICT, even if turned off, is slow. It ends up calling > php_verror to construct the entire error string before it checks and > se

Re: [PHP-DEV] json_encode()

2008-12-15 Thread Stan Vassilev | FM
Hi, JSON allows extensions. I can not understand why this is not an extension that makes sense: json_encode($var, $allowScalar = false); In PHP outputting of JS literals is a common action, so all you'll achieve by completely removing this option, is forcing people to go from this: echo '

Re: [PHP-DEV] json_encode()

2008-12-15 Thread mike
On Mon, Dec 15, 2008 at 8:58 PM, Mark Karpeles wrote: > I believe part of the job should be the programmer's job too. I'm a programmer. I expect json_* functions to encode and decode to JSON specifications. Not PHP's original interpretation of it... > Lazy mode is "not that good", as it's going

Re: [PHP-DEV] json_encode()

2008-12-15 Thread Mark Karpeles
Hi, I believe part of the job should be the programmer's job too. json_encode() is way too useful to pass things to javascript (the other way around is not that easy, but I have a function called "JSparse" which work nicely with .toSource() output, and an implementation of .toSource() for MSIE, I

Re: [PHP-DEV] json_encode()

2008-12-15 Thread mike
On Mon, Dec 15, 2008 at 1:43 PM, John Carter -X (johncart - PolicyApp Ltd at Cisco) wrote: > How about a strict mode added to the list of the current json_encode() > options? > > That way current code will continue to work and anyone reading the docs > will know the default behaviour isn't strictl

Re: [PHP-DEV] json_encode()

2008-12-15 Thread Rasmus Lerdorf
Edward Z. Yang wrote: > Jared Williams wrote: >> Don't think that's what he said... More like... >> >> assert(is_object($foo) || is_array($foo)); // ensure strictly conforming >> $json = json_encode($foo); > > Which is, for all intents and purposes, the same thing. (Since you can't > pass json_enc

RE: [PHP-DEV] json_encode()

2008-12-15 Thread John Carter -X (johncart - PolicyApp Ltd at Cisco)
How about a strict mode added to the list of the current json_encode() options? That way current code will continue to work and anyone reading the docs will know the default behaviour isn't strictly correct. John. John Carter Development Manager NAC Governance Server Cisco johnc...@cisco.com +44

Re: [PHP-DEV] json_encode()

2008-12-15 Thread mike
On Mon, Dec 15, 2008 at 1:10 PM, troels knak-nielsen wrote: > I, for one, think that the only sane choices are 1 or 2. The third > option is way too magic, and will end up confusing people. In that case I would have to go for #2. Personally I want to see PHP be as standards-compliant and compat

Re: [PHP-DEV] json_encode()

2008-12-15 Thread troels knak-nielsen
On Mon, Dec 15, 2008 at 10:02 PM, mike wrote: > I'd like to see it "do the right thing" in PHP 6, and perhaps if I think everybody agrees to that. The question at hand, is what the right thing is. I, for one, think that the only sane choices are 1 or 2. The third option is way too magic, and wil

Re: [PHP-DEV] json_encode()

2008-12-15 Thread mike
On Mon, Dec 15, 2008 at 12:55 PM, Uwe Schindler wrote: > As is noted in an earlier mail, I would prefer 1 (simply document it in the > function description). In my opinion, if somebody then passes a basic type > to json_encode he is aware of what he is doing (hopefully). > > For compatibility with

RE: [PHP-DEV] json_encode()

2008-12-15 Thread Uwe Schindler
As is noted in an earlier mail, I would prefer 1 (simply document it in the function description). In my opinion, if somebody then passes a basic type to json_encode he is aware of what he is doing (hopefully). For compatibility with current code and securely escaping strings for javascript it is

Re: [PHP-DEV] json_encode()

2008-12-15 Thread Edward Z. Yang
Jared Williams wrote: > Don't think that's what he said... More like... > > assert(is_object($foo) || is_array($foo)); // ensure strictly conforming > $json = json_encode($foo); Which is, for all intents and purposes, the same thing. (Since you can't pass json_encode(34) for strict JSON). PHP ha

RE: [PHP-DEV] json_encode()

2008-12-15 Thread Jared Williams
> -Original Message- > From: mike [mailto:mike...@gmail.com] > Sent: 15 December 2008 18:10 > To: Rasmus Lerdorf > Cc: PHP Developers Mailing List > Subject: Re: [PHP-DEV] json_encode() > > On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf > wrote: > &g

Re: [PHP-DEV] json_encode()

2008-12-15 Thread mike
On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf wrote: > 1. Document the fact that if you want to strictly conform to the JSON > spec and be sure your json_encode output will work in various JSON > parsers, you have to pass it a PHP array or object. Instead of json_encode(34) the suggestion

Re: [PHP-DEV] json_encode ignores protected/private class members

2008-10-16 Thread Lukas Kahwe Smith
Hi, So I guess the conclusion is: Create a feature request ticket, take the information from this thread and put it into the ticket .. and ideally write a patch yourself or motivate someone else .. regards, Lukas -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit

Re: [PHP-DEV] json_encode ignores protected/private class members

2008-10-12 Thread Daniel Convissor
Hi Jaris: > I don't know if I'm using json_encode for something it's not supposed to > do. I'm using it to serialize an object to send it to another > runtime-environment in response to an remote call, just like what I can > do with SOAP, REST or RMI. In this context I don't see much sense i

Re: [PHP-DEV] json_encode ignores protected/private class members

2008-10-10 Thread Richard Quadling
2008/10/9 Rodrigo Saboya <[EMAIL PROTECTED]>: > Jarismar Chaves da Silva wrote: >> >> I agree with you. >> But when using json_encode I believe the developer wants to transfer the >> complete object state, just like when using serialize. >> Serialize does see private/protected class members, while

Re: [PHP-DEV] json_encode ignores protected/private class members

2008-10-10 Thread Richard Quadling
2008/10/10 Jarismar Chaves da Silva <[EMAIL PROTECTED]>: > > > Rodrigo Saboya wrote: >> >> Jarismar Chaves da Silva wrote: >>> >>> I agree with you. >>> But when using json_encode I believe the developer wants to transfer the >>> complete object state, just like when using serialize. >>> Serialize

Re: [PHP-DEV] json_encode ignores protected/private class members

2008-10-10 Thread Jarismar Chaves da Silva
Rodrigo Saboya wrote: Jarismar Chaves da Silva wrote: I agree with you. But when using json_encode I believe the developer wants to transfer the complete object state, just like when using serialize. Serialize does see private/protected class members, while json_encode not. Javascript does n

Re: [PHP-DEV] json_encode ignores protected/private class members

2008-10-09 Thread Rodrigo Saboya
Jarismar Chaves da Silva wrote: I agree with you. But when using json_encode I believe the developer wants to transfer the complete object state, just like when using serialize. Serialize does see private/protected class members, while json_encode not. Javascript does not have class-accessors s

Re: [PHP-DEV] json_encode ignores protected/private class members

2008-10-09 Thread Jarismar Chaves da Silva
Yes, it like it too. Just like an OOP should be. Dave Ingram wrote: however changing this at this point would be a huge security issue, so if at all, it would need to be handled by an optional parameter that defaults to false. That would be unclean. If it's implemented in some way, j

  1   2   >