Req #68456 [ReO]: json_decode should be able to treat all numbers as strings

From: Date: Wed, 22 Apr 2015 17:26:18 +0000
Subject: Req #68456 [ReO]: json_decode should be able to treat all numbers as strings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192278@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68456&edit=1 ID: 68456 Updated by: bukka@php.net Reported by: admin at bittylicious dot com Summary: json_decode should be able to treat all numbers as strings Status: Re-Opened Type: Feature/Change Request Package: JSON related Operating System: Linux Wheezy PHP Version: 5.4.35 Assigned To: bukka Block user comment: N Private report: N New Comment: As I said I don't think that adding new flags is the best solution but it's also true that properly implementing json schema will take much longer and it's a relatively big feature. Ok then I will let the PHP members decide. It means that I will proceed with the RFC. I will need to add more info into it but will probably put it under discussion in the next few weeks. Previous Comments: ------------------------------------------------------------------------ [2015-04-19 22:12:43] yohgaki@php.net Related bug https://bugs.php.net/bug.php?id=69422 ------------------------------------------------------------------------ [2015-04-19 19:32:17] admin at bittylicious dot com Thanks for discussing this on the mailing list - good to hear there are some positive comments too. I still think this, simpler version should be implemented. We already have JSON_BIGINT_AS_STRING so it seems as though it could be argued as plugging a missing option rather than a full on enhancement as such. Going the whole hog and allowing object hints etc., is far larger than this; having this fix go in means that users can implement "casting" to objects manually, but I have no even remotely-nice workaround I can use to handle these float values at all at present. ------------------------------------------------------------------------ [2015-04-19 19:09:26] bukka@php.net Just a quick update. We had a discussion about it on internal list: http://bit.ly/1D2ZyAR . I also started RFC to propose addition of float and int to string flags: https://wiki.php.net/rfc/json_numeric_as_string . However I have been thinking about that a lot and I don't think it would be a proper way how to fix this. Such flag would influence all float values and it's limited only to string. I think that better solution would be to introduce support for json schema validation that could be also extended as a sort of type hints for supplied json. Then it would be possible to select just specific values and use whatever types (e.g. objects or string). It's a relativaly bigger feature so it might take a bit longer but I think that it's a proper way of fixing this. ------------------------------------------------------------------------ [2015-03-15 21:17:21] admin at bittylicious dot com Fab stuff, thanks so much for examining this. Great to hear that the encode functionality is also under consideration too. ------------------------------------------------------------------------ [2015-03-15 20:06:28] bukka@php.net That makes sense. I'm a bit dump so it took me a bit... :) I actually recently closed something similar for encode so the constant could be used in both ways. I'd imagine something like JSON_DOUBLE_TO_STRING . I'll try to put together a quick RFC for 5.6 up (with choice for 7 only) next week and if it gets in, I will do the patch. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=68456 -- Edit this bug report at https://bugs.php.net/bug.php?id=68456&edit=1

« previous php.bugs (#192278) next »