|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-04-10 21:57 UTC] yohgaki@php.net
Description: ------------ Currently, json_encode() encode PHP int/float/bool as JSON numeric(int/float) and bool. Since JSON numeric does not map to PHP int/float as JSON numeric could be any precision, large numbers need to be stored as "string" which is converted to JSON string. Some "string" needed to be encoded as numeric. To do that json_encode() needs some kind of specification to encode data as programmer intended. http://json-schema.org/examples.html This could be used as the specification. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 21:00:01 2025 UTC |
Hello, I propose an incomplete solution but it may solve some problems. Like array_intersect() we could do : class ExpectedObject { string $test; float $poc; } $obj = json_decode_spec('{"test":1234567890.12345678, "poc": "1Gm", "key":'val'}', ExpectedObject::class, ...); var_dump($obj); object(ExpectedObject)#1 { test => (string) '1234567890.12345678' poc => (float) 1.0 } Regards