El sáb, 27 ago 2022 a las 1:31, juan carlos morales (<dev.juan.mora...@gmail.com>) escribió: > > === Open issues/concerns === > > > @@@ Usage of JSON_INVALID_UTF8_IGNORE @@@ > > - I have my doubts now, because of this codes: > > ``` > <php > > var_dump(json_validate("\"a\xb0b\""), json_last_error_msg()); > var_dump("------------"); > var_dump(json_validate("\"a\xb0b\"", 512, JSON_INVALID_UTF8_IGNORE), > json_last_error_msg()); > ``` > > Results: > > bool(false) > string(56) "Malformed UTF-8 characters, possibly incorrectly encoded" > string(12) "------------" > bool(true) > string(8) "No error" > > > Gives different results, but ... > > ``` > <?php > > var_dump(json_decode("{ \"a\xb0b\" : \"dummy\" }"), json_last_error_msg()); > var_dump("------------"); > var_dump(json_decode("{ \"a\xb0b\" : \"dummy\" }", 512, > JSON_INVALID_UTF8_IGNORE), json_last_error_msg()); > ``` > > Results in: > NULL > string(56) "Malformed UTF-8 characters, possibly incorrectly encoded" > string(12) "------------" > NULL > string(56) "Malformed UTF-8 characters, possibly incorrectly encoded" > > > > So at a first look, seems the flag should also be remove, as with > json_validate() we say its valid, but then on json_decode() we get > NULL, even with the JSON_INVALID_UTF8_IGNORE provided; does not make > sense I believe. > > What do you think? Is there a use case I am missing here? Is this flag > worth to have still? >
I made a huge mistake sorry, long day here, 1:30 am , the code for json_decode should be as: var_dump(json_decode("{ \"a\xb0b\" : \"dummy\" }"), true, 512, json_last_error_msg()); var_dump("------------"); var_dump(json_decode("{ \"a\xb0b\" : \"dummy\" }", true, 512, JSON_INVALID_UTF8_IGNORE), json_last_error_msg()); Resulting in NULL bool(true) int(512) string(56) "Malformed UTF-8 characters, possibly incorrectly encoded" string(12)"------------" array(1) { ["ab"]=> string(5) "dummy" } string(8) "No error" Saying so, now ... yes I support the usage of the JSON_INVALID_UTF8_IGNORE , as json_validate() result goes in the same direction with json_decode(). I think we need to have this flag. RFC: https://wiki.php.net/rfc/json_validate Implementation: https://github.com/php/php-src/pull/9399 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php