Hi,
I would like to add a new option to JSON for dealing with large floats. The
use case is mainly for decoder but can be used for encoder as well.
JSON_FLOAT_AS_STRING
decode: all float values will be decoded as string
- It's often an issue for very large float values with many fractional
digits that are coming from platforms that support larger float
representation than double. In that case the conversion is lost and there
is no way how to get it back (see http://bugs.php.net/68456 [pls ignore my
initial dump comments when I didn't get the issue :)] and an example of the
lost precision here http://3v4l.org/80iCh ). Converting the value to string
keep the precision and resolves the problem.
encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptable
I think that this is more a bugfix as the precision is lost without any way
how to get it back (except pre-processing json string with regular
expression). I would like to add it to 5.6.x if there are no objections?
Cheers
Jakub
Hi Jakub,
I would like to add a new option to JSON for dealing with large floats. The
use case is mainly for decoder but can be used for encoder as well.JSON_FLOAT_AS_STRING
decode: all float values will be decoded as string
- It's often an issue for very large float values with many fractional
digits that are coming from platforms that support larger float
representation than double. In that case the conversion is lost and there
is no way how to get it back (see http://bugs.php.net/68456 [pls ignore my
initial dump comments when I didn't get the issue :)] and an example of the
lost precision here http://3v4l.org/80iCh ). Converting the value to
string
keep the precision and resolves the problem.encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptableI think that this is more a bugfix as the precision is lost without any way
how to get it back (except pre-processing json string with regular
expression). I would like to add it to 5.6.x if there are no objections?
Converting int/float to PHP native type is obvious bug.
We must consider compatibility for released versions, so
+1 for adding JSON_FLOAT_AS_STRING option.
"int" should be fixed also.
http://3v4l.org/95dHM
So option may be JSON_SCALAR_AS_STRING or
additional JSON_INT_AS_STRING.
PHP7 should have string scalars by default. IMHO.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi all,
Hi Jakub,
I would like to add a new option to JSON for dealing with large floats.
The
use case is mainly for decoder but can be used for encoder as well.JSON_FLOAT_AS_STRING
decode: all float values will be decoded as string
- It's often an issue for very large float values with many fractional
digits that are coming from platforms that support larger float
representation than double. In that case the conversion is lost and there
is no way how to get it back (see http://bugs.php.net/68456 [pls ignore
my
initial dump comments when I didn't get the issue :)] and an example of
the
lost precision here http://3v4l.org/80iCh ). Converting the value to
string
keep the precision and resolves the problem.encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptableI think that this is more a bugfix as the precision is lost without any
way
how to get it back (except pre-processing json string with regular
expression). I would like to add it to 5.6.x if there are no objections?Converting int/float to PHP native type is obvious bug.
We must consider compatibility for released versions, so
+1 for adding JSON_FLOAT_AS_STRING option."int" should be fixed also.
http://3v4l.org/95dHMSo option may be JSON_SCALAR_AS_STRING or
additional JSON_INT_AS_STRING.PHP7 should have string scalars by default. IMHO.
I didn't notice this bug before. This bug make me worry that new PHP7
type hint will create a lot of type casting bugs because even C programmer
makes this kind of design mistake...
If it's possible, coercive STH for weak type hint mode will help to reduce
type casting bugs. IMHO.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi all,
Hi Jakub,
I would like to add a new option to JSON for dealing with large floats.
The
use case is mainly for decoder but can be used for encoder as well.JSON_FLOAT_AS_STRING
decode: all float values will be decoded as string
- It's often an issue for very large float values with many fractional
digits that are coming from platforms that support larger float
representation than double. In that case the conversion is lost and there
is no way how to get it back (see http://bugs.php.net/68456 [pls ignore
my
initial dump comments when I didn't get the issue :)] and an example of
the
lost precision here http://3v4l.org/80iCh ). Converting the value to
string
keep the precision and resolves the problem.encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptableI think that this is more a bugfix as the precision is lost without any
way
how to get it back (except pre-processing json string with regular
expression). I would like to add it to 5.6.x if there are no objections?Converting int/float to PHP native type is obvious bug.
We must consider compatibility for released versions, so
+1 for adding JSON_FLOAT_AS_STRING option."int" should be fixed also.
http://3v4l.org/95dHMSo option may be JSON_SCALAR_AS_STRING or
additional JSON_INT_AS_STRING.PHP7 should have string scalars by default. IMHO.
I didn't notice this bug before. This bug make me worry that new PHP7
type hint will create a lot of type casting bugs because even C programmer
makes this kind of design mistake...If it's possible, coercive STH for weak type hint mode will help to reduce
type casting bugs. IMHO.
Same effects but totally unrelated topics. All functions dealing with
large external numbers had the same issues, since ever. It has nothing
to do with STH.
Cheers,
Pierre
@pierrejoye | http://www.libgd.org
Hi Pierre,
Same effects but totally unrelated topics. All functions dealing with
large external numbers had the same issues, since ever. It has nothing
to do with STH.
Yes, it is.
Developers make casting mistakes like this even when they are used to
strict typing.
This make me worry about wrong casting usage with PHP7.
For example,
$db->findById($id);
The method prototype should be
function findById(string $id)
to be correct.
I think there will be many users write wrong code such as
function findById(int $id)
One may argue most systems are 64 bit anyway and would not be much issue.
However, many IoT devices uses 32 bit OS still. 32 bit systems cannot be
ignored yet.
User will cast $id to int without thinking the consequence. This could
create
security hole as (int)$id for string results in 0/negative value.
Casting external values to int/float is wrong and evil simply. Current type
hint
encourages/requires casts even if users are not realizing the consequence
fully.
We do make mistake like this bug. We cannot assume PHP user will not.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Pierre,
Same effects but totally unrelated topics. All functions dealing with
large external numbers had the same issues, since ever. It has nothing
to do with STH.Yes, it is.
Developers make casting mistakes like this even when they are used to strict
typing.
I understand and this is why I said it is the same symptom. But JSON
or any other external data decoding has nothing to do with STH. It
would be nice to do not clutter this discussion with yet another STH
argument :)
Hi Pierre,
Hi Pierre,
On Mon, Mar 30, 2015 at 10:54 AM, Pierre Joye pierre.php@gmail.com
wrote:Same effects but totally unrelated topics. All functions dealing with
large external numbers had the same issues, since ever. It has nothing
to do with STH.Yes, it is.
Developers make casting mistakes like this even when they are used to
strict
typing.I understand and this is why I said it is the same symptom. But JSON
or any other external data decoding has nothing to do with STH. It
would be nice to do not clutter this discussion with yet another STH
argument :)
As you know, I'm an very unhappy person with the accepted RFC :)
Since Zeev closed the vote before the end date, I think we may have a little
chance to improve weak mode scalar type hint. i.e. Use Zeev's RFC for weak
mode.
Anyway, similar issue is not only external but also PHP internal.
For example,
[yohgaki@dev php-src]$ ./php-bin -r 'var_dump(["999999999999999999999"=>1,
999999999999999999999=>1]);'
array(2) {
["999999999999999999999"]=>
int(1)
[3875820019684212736]=>
int(1)
}
Library that deals with array should use "string" key data type to have
correct key for
any number even when library expects integer keys. i.e. The library must
have "string" type hint for integer key to achieve correct behavior.
Database, JSON and array are good examples of confusions. Smart developers
will use "string" type hints for these, while less experienced developers
will use
"int/float" type hints for these. When users have to use both of them,
users are
forced to casting variable between "string" and "int/float". This makes
impossible
to write "correct" code. This JSON bug is a proof that this will happen.
I just don't see the point to introduce new feature that makes impossible
to write
correct code while there is good solution. Fortunately, we still have time
to address
this.
Regards,
P.S. Does anyone have alternative ideas for this?
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Pierre,
On Mon, Mar 30, 2015 at 11:42 AM, Pierre Joye pierre.php@gmail.com
wrote:Hi Pierre,
On Mon, Mar 30, 2015 at 10:54 AM, Pierre Joye pierre.php@gmail.com
wrote:Same effects but totally unrelated topics. All functions dealing with
large external numbers had the same issues, since ever. It has nothing
to do with STH.Yes, it is.
Developers make casting mistakes like this even when they are used to
strict
typing.I understand and this is why I said it is the same symptom. But JSON
or any other external data decoding has nothing to do with STH. It
would be nice to do not clutter this discussion with yet another STH
argument :)As you know, I'm an very unhappy person with the accepted RFC :)
Since Zeev closed the vote before the end date, I think we may have a
little
chance to improve weak mode scalar type hint. i.e. Use Zeev's RFC for weak
mode.Anyway, similar issue is not only external but also PHP internal.
For example,[yohgaki@dev php-src]$ ./php-bin -r
'var_dump(["999999999999999999999"=>1, 999999999999999999999=>1]);'
array(2) {
["999999999999999999999"]=>
int(1)
[3875820019684212736]=>
int(1)
}Library that deals with array should use "string" key data type to have
correct key for
any number even when library expects integer keys. i.e. The library must
have "string" type hint for integer key to achieve correct behavior.Database, JSON and array are good examples of confusions. Smart developers
will use "string" type hints for these, while less experienced developers
will use
"int/float" type hints for these. When users have to use both of them,
users are
forced to casting variable between "string" and "int/float". This makes
impossible
to write "correct" code. This JSON bug is a proof that this will happen.I just don't see the point to introduce new feature that makes impossible
to write
correct code while there is good solution. Fortunately, we still have time
to address
this.Regards,
P.S. Does anyone have alternative ideas for this?
Please can this be discussed in a new thread? This thread is just about
adding a new option to json ext.
Cheers
Jakub
Hi Yasuo
"int" should be fixed also.
http://3v4l.org/95dHM
We have already fix for this: JSON_BIGINT_AS_STRING
( http://3v4l.org/vYXUk
)
So option may be JSON_SCALAR_AS_STRING or
additional JSON_INT_AS_STRING.
I was actually thinking about JSON_INT_AS_STRING anyway as it might be
useful for type consistency in decoding (when decoding number that are
close to bigint limit) and allowing safe encoding from 64bit to 32bit.
However this is a bit more controversial so I plan to open a new thread
about it.
Cheers
Jakub
Hi Jakub,
"int" should be fixed also.
http://3v4l.org/95dHMWe have already fix for this:
JSON_BIGINT_AS_STRING
(
http://3v4l.org/vYXUk )
Excellent.
So option may be JSON_SCALAR_AS_STRING or
additional JSON_INT_AS_STRING.I was actually thinking about JSON_INT_AS_STRING anyway as it might be
useful for type consistency in decoding (when decoding number that are
close to bigint limit) and allowing safe encoding from 64bit to 32bit.
However this is a bit more controversial so I plan to open a new thread
about it.
There are too many options (4 options to be exact) for JSON to work safely
under HTML context currently. If user would not like to loose int/float
information, 6 options are needed. Number of options are better to be
reduced, so big +1 for string raw data by default. It may be better to have
JSON_HEX_HTML_CHARS = JSON_HEX_TAG
| JSON_HEX_AMP
| JSON_HEX_APOS
|
JSON_HEX_QUOT
also.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Yasuo,
There are too many options (4 options to be exact) for JSON to work safely
under HTML context currently. If user would not like to loose int/float
information, 6 options are needed. Number of options are better to be
reduced, so big +1 for string raw data by default. It may be better to haveJSON_HEX_HTML_CHARS =
JSON_HEX_TAG
|JSON_HEX_AMP
|JSON_HEX_APOS
|
JSON_HEX_QUOT
It might make sense to introduce something like that. I'm not sure about
the name but definitely will think about that and possibly open a new email
thread as it's again a bit off topic :)
Cheers
Jakub
Hi!
JSON_FLOAT_AS_STRING
decode: all float values will be decoded as string
- It's often an issue for very large float values with many fractional
digits that are coming from platforms that support larger float
representation than double. In that case the conversion is lost and there
is no way how to get it back (see http://bugs.php.net/68456 [pls ignore my
initial dump comments when I didn't get the issue :)] and an example of the
lost precision here http://3v4l.org/80iCh ). Converting the value to string
keep the precision and resolves the problem.
This makes sense, though one should be careful as string and float is
not the same and if you re-encode it, you will have data corruption
(since if somebody using, say, Java, decodes it they'd have string where
it expects float and decoding will likely fail). But I guess since it is
an option, people that enable it will have to deal with it, e.g. by
never re-encoding the data back.
encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptable
Here I'm not sure it makes much sense though. If it's float, it should
be float. It's valid JSON, so if the receiving side can not handle it,
it's their issue which they have to fix in their decoding. Just changing
the types of data when encoding JSON does not sound like a good idea.
Especially given that the reader may be some library like Java's
Jackson, where types are very important. Of course, we could add tons of
options like INT_AS_STRING, OBJECT_AS_STRING, etc. but I don't think
this is what json encoder should be doing.
I think that this is more a bugfix as the precision is lost without any way
I don't see how it is a bugfix. Representing floats is imprecise, it is
known and not a bug. json_encode now produces completely valid
representation of the data, so no bug there either. I don't think
changing value types on encoding is a good idea.
Stas Malyshev
smalyshev@gmail.com
Hi Stas
On Wed, Apr 1, 2015 at 7:58 AM, Stanislav Malyshev smalyshev@gmail.com
wrote:
encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptableHere I'm not sure it makes much sense though. If it's float, it should
be float. It's valid JSON, so if the receiving side can not handle it,
it's their issue which they have to fix in their decoding. Just changing
the types of data when encoding JSON does not sound like a good idea.
Especially given that the reader may be some library like Java's
Jackson, where types are very important. Of course, we could add tons of
options like INT_AS_STRING, OBJECT_AS_STRING, etc. but I don't think
this is what json encoder should be doing.
The encoding was just about re-using it. I wouldn't probably propose such
constant if it was just for encoding (the main purpose is decoding though).
I just thought that it could be a good idea to have some usage for encoder
if it's added. It seemed to me better than just ignore it completely for
encoder. What do you think?
I think that this is more a bugfix as the precision is lost without any
wayI don't see how it is a bugfix. Representing floats is imprecise, it is
known and not a bug. json_encode now produces completely valid
representation of the data, so no bug there either. I don't think
changing value types on encoding is a good idea.
I didn't mean it for json_encode ( apology for that as it might have seemed
that is related just to json_encode). I meant it just as "a sort of" bug
for json_decode as we loose information without giving user any way how to
prevent it or at least some note in documentation about that.
Cheers
Jakub
Hi!
The encoding was just about re-using it. I wouldn't probably propose
such constant if it was just for encoding (the main purpose is decoding
though). I just thought that it could be a good idea to have some usage
for encoder if it's added. It seemed to me better than just ignore it
completely for encoder. What do you think?
I'd have encoder to ignore it.
I didn't mean it for json_encode ( apology for that as it might have
seemed that is related just to json_encode). I meant it just as "a sort
of" bug for json_decode as we loose information without giving user any
way how to prevent it or at least some note in documentation about that.
It's not actually a bug - as I said, nobody who knows anything about how
computers do numbers expects exact representation of floats. That said,
ability to somehow accept numbers which don't fit current precision
may be useful in some corner cases, especially when you are
interoperating with systems with different number sizes. As the old
principle goes, be liberal in what you accept and conservative in what
you produce. json_decode()
option would fit this principle well.
--
Stas Malyshev
smalyshev@gmail.com
Hi,
After bit of thinking I realised that it will be better to go with RFC and
created an initial draft https://wiki.php.net/rfc/json_numeric_as_string .
The thing that there are users asking for similar functionality for ints
which is a bit controversial so it's better to have a RFC for that and also
let people decide about the proposed version. Please don't comment on it
till I put it under discussion (it's not completed yet).
On Wed, Apr 1, 2015 at 8:07 PM, Stanislav Malyshev smalyshev@gmail.com
wrote:
Hi!
The encoding was just about re-using it. I wouldn't probably propose
such constant if it was just for encoding (the main purpose is decoding
though). I just thought that it could be a good idea to have some usage
for encoder if it's added. It seemed to me better than just ignore it
completely for encoder. What do you think?I'd have encoder to ignore it.
I will add a voting options for that to the prepared RFC.
I didn't mean it for json_encode ( apology for that as it might have
seemed that is related just to json_encode). I meant it just as "a sort
of" bug for json_decode as we loose information without giving user any
way how to prevent it or at least some note in documentation about that.It's not actually a bug - as I said, nobody who knows anything about how
computers do numbers expects exact representation of floats. That said,
ability to somehow accept numbers which don't fit current precision
may be useful in some corner cases, especially when you are
interoperating with systems with different number sizes. As the old
principle goes, be liberal in what you accept and conservative in what
you produce.json_decode()
option would fit this principle well.
I still think that this is not just a useful feature. The thing is that a
user has no way to get complete information from the supplied json. The
json is valid for any float value (there are no limits on precision in the
spec) and we don't allow to keep that information. That's a problem and it
doesn't matter if we call it a bug or something else!
Cheers
Jakub
Hi Jakub,
I would like to add a new option to JSON for dealing with large floats. The
use case is mainly for decoder but can be used for encoder as well.JSON_FLOAT_AS_STRING
decode: all float values will be decoded as string
- It's often an issue for very large float values with many fractional
digits that are coming from platforms that support larger float
representation than double. In that case the conversion is lost and there
is no way how to get it back (see http://bugs.php.net/68456 [pls ignore my
initial dump comments when I didn't get the issue :)] and an example of the
lost precision here http://3v4l.org/80iCh ). Converting the value to
string
keep the precision and resolves the problem.encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptableI think that this is more a bugfix as the precision is lost without any way
how to get it back (except pre-processing json string with regular
expression). I would like to add it to 5.6.x if there are no objections?
Could you add "json_encode" type hint also?
Large int/float must be treated as string or GMP object (we don't have GMP
float yet, though)
Currently, there is no way to encode large "numeric" JSON data correctly
when it is stored as
string.
string json_encode ( mixed $value [, int $options = 0 [, int $depth = 512
[, array $type_spec = NULL]]] )
where $type_spec specifies correct data representation. i.e. numeric,
string, bool
json_encode()
type hint should work like Zeev's type hint.
i.e. No data type conversion, but validate its content.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Yasuo,
Could you add "json_encode" type hint also?
Large int/float must be treated as string or GMP object (we don't have GMP
float yet, though)
Currently, there is no way to encode large "numeric" JSON data correctly
when it is stored as
string.string json_encode ( mixed $value [, int $options = 0 [, int $depth = 512
[, array $type_spec = NULL]]] )where $type_spec specifies correct data representation. i.e. numeric,
string, bool
json_encode()
type hint should work like Zeev's type hint.
i.e. No data type conversion, but validate its content.
Again this is a bit off-topic. I think that it would be good if you could
create a bug report for this. It would be great to add an example how the
$type_spec should work (e.g. if you mean something like
http://json-schema.org/examples.html )
Cheers
Jakub
Hi Jakub,
Could you add "json_encode" type hint also?
Large int/float must be treated as string or GMP object (we don't have
GMP float yet, though)Currently, there is no way to encode large "numeric" JSON data correctly
when it is stored as
string.string json_encode ( mixed $value [, int $options = 0 [, int $depth = 512
[, array $type_spec = NULL]]] )where $type_spec specifies correct data representation. i.e. numeric,
string, bool
json_encode()
type hint should work like Zeev's type hint.
i.e. No data type conversion, but validate its content.Again this is a bit off-topic. I think that it would be good if you could
create a bug report for this. It would be great to add an example how the
$type_spec should work (e.g. if you mean something like
http://json-schema.org/examples.html )
Yes.
We need something like this to make jason_encode() work as it should.
FR is added.
https://bugs.php.net/bug.php?id=69422
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
I would like to add a new option to JSON for dealing with large floats. The
use case is mainly for decoder but can be used for encoder as well.JSON_FLOAT_AS_STRING
decode: all float values will be decoded as string
- It's often an issue for very large float values with many fractional
digits that are coming from platforms that support larger float
representation than double. In that case the conversion is lost and there
is no way how to get it back (see http://bugs.php.net/68456 [pls ignore my
initial dump comments when I didn't get the issue :)] and an example of the
lost precision here http://3v4l.org/80iCh ). Converting the value to string
keep the precision and resolves the problem.encode: all float values will be encoded as string
- re-using the constant for encoder makes sense if PHP creates JSON for
platform that support lower float type (e.g. C float) and the precision
loss is not acceptableI think that this is more a bugfix as the precision is lost without any way
how to get it back (except pre-processing json string with regular
expression). I would like to add it to 5.6.x if there are no objections?
Feels a bit hackish
I think it is possible to introduce an overall better solution
We can expose result of json-tokenizing as a tree of objects:
JSON\Object
JSON\Array
JSON\String
JSON\Number
JSON\False
JSON\True
JSON\Null
then, it would be possible to introduce any number of experimental userland implementations like the one proposed here
--
Alexey Zakhlestin
https://github.com/indeyets
PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc
Feels a bit hackish
I think it is possible to introduce an overall better solutionWe can expose result of json-tokenizing as a tree of objects:
JSON\Object
JSON\Array
JSON\String
JSON\Number
JSON\False
JSON\True
JSON\Nullthen, it would be possible to introduce any number of experimental userland implementations like the one proposed here
I decided to elaborate
<?php
namespace JSON;
abstract class Value
{
public function toJson();
public function toNative(); // this would do, whatever json_decode does
}
class Object extends Value implements \ArrayAccess, \IteratorAggregate
{
}
class Array extends Value implements \ArrayAccess, \IteratorAggregate
{
}
abstract class Literal extends Value
{
public function toString();
public function __toString()
{
return $this->toString();
}
}
class String extends Literal
{
}
class Number extends Literal
{
public function toInt();
public function toFloat();
}
class False extends Literal
{
}
class True extends Literal
{
}
class Null extends Literal
{
}
So, in case of Number, there would be a way to get the value the way it was stored in document using toString(), use toInt() or toFloat() to get a value with possible precision loss or use toNative(), which would be “smart” and return int or float using the same logic, which json_decode()
uses now.
It would work the other way round too. Object::toJson() would return json-representation of the tree.
Hi,
On Tue, Apr 14, 2015 at 7:33 AM, Alexey Zakhlestin indeyets@gmail.com
wrote:
Feels a bit hackish
I think it is possible to introduce an overall better solutionWe can expose result of json-tokenizing as a tree of objects:
JSON\Object
JSON\Array
JSON\String
JSON\Number
JSON\False
JSON\True
JSON\Nullthen, it would be possible to introduce any number of experimental
userland implementations like the one proposed hereI decided to elaborate
<?php namespace JSON; abstract class Value { public function toJson(); public function toNative(); // this would do, whatever
json_decode does
}class Object extends Value implements \ArrayAccess, \IteratorAggregate { } class Array extends Value implements \ArrayAccess, \IteratorAggregate { } abstract class Literal extends Value { public function toString(); public function __toString() { return $this->toString(); } } class String extends Literal { } class Number extends Literal { public function toInt(); public function toFloat(); } class False extends Literal { } class True extends Literal { } class Null extends Literal { }
So, in case of Number, there would be a way to get the value the way it
was stored in document using toString(), use toInt() or toFloat() to get a
value with possible precision loss or use toNative(), which would be
“smart” and return int or float using the same logic, whichjson_decode()
uses now.It would work the other way round too. Object::toJson() would return
json-representation of the tree.
This could of course can't be introduced as a default (at least not in 7)
as it's a huge BC break. I don't like introducing too many new flags either
(it might be the case that you would like to use this just for objects but
not for Literals). Also it can't be mixed (meaning you can't have some
values as int and some as Json\Number). However I think this could work
nicely with json-scheme type hints and using that only if explicitly
specified in the scheme. The only problem is that it's not a small feature
so it will probably take some time to make that happen.
JSON_FLOAT_AS_STRING is meant like a quick fix for something that is
causing issue. However I it's a bit "hackish" as it applies on all floats
which is not very nice. Maybe it will really make sense to wait for
json-scheme. More I look into more I think that it would be a better
solution.
Cheers
Jakub