Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.
Any chance this could get committed to 5.2+
Index: tests/002.phpt
RCS file: /repository/php-src/ext/json/tests/002.phpt,v
retrieving revision 1.3
diff -u -r1.3 002.phpt
--- tests/002.phpt 27 May 2008 18:16:03 -0000 1.3
+++ tests/002.phpt 2 Mar 2009 16:16:13 -0000
@@ -1,4 +1,4 @@
---TEST--
+--TEST--
json_encode()
tests
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
@@ -8,8 +8,14 @@
var_dump(json_encode(""));
var_dump(json_encode(NULL));
var_dump(json_encode(TRUE));
var_dump(json_encode(array(""=>"")));
var_dump(json_encode(array(array(1))));
+var_dump(json_encode(array());
+var_dump(json_encode(array(""=>"")), PHP_JSON_FORCE_HASH);
+var_dump(json_encode(array(array(1))),PHP_JSON_FORCE_HASH);
+var_dump(json_encode(array(),PHP_JSON_FORCE_HASH);
var_dump(json_encode(1));
var_dump(json_encode("руссиш"));
@@ -23,6 +29,10 @@
string(4) "true"
string(7) "{"":""}"
string(5) "[[1]]"
+string(2) "[]"
+string(7) "{"":""}"
+string(15) "{"0":{"0":"1"}}"
+string(2) "{}"
string(1) "1"
string(38) ""\u0440\u0443\u0441\u0441\u0438\u0448""
Done
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
Richard Quadling wrote:
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
I'm too convinced of the parameter name and I don't think its something
that should be added to 5.2.9 since its a feature.
Scott
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
I'm too convinced of the parameter name and I don't think its something
that should be added to 5.2.9 since its a feature.Scott
5.3+ would be OK then.
As to the param name, I'm not actually changing the name, just adding
another flag.
In javascript's terminology,the output is an array ...
[]
or a hash
{}
So forcing a hash for arrays is pretty much what would be wanted and I
as I comment in the request, we have a "force" option when coming FROM
json data ... json_decode ( string $json [, bool $assoc= false [, int
$depth= 512 ]] )
And the "name" of the param here is appropriate to PHP's use (assoc is
not part of JSON's or JS's terminology).
If you can think of a better name for the flag, then I'd be glad to use it.
Richard.
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
Richard Quadling wrote:
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
I'm too convinced of the parameter name and I don't think its something
that should be added to 5.2.9 since its a feature.Scott
5.3+ would be OK then.
As to the param name, I'm not actually changing the name, just adding
another flag.In javascript's terminology,the output is an array ...
[]
or a hash
{}
So forcing a hash for arrays is pretty much what would be wanted and I
as I comment in the request, we have a "force" option when coming FROM
json data ... json_decode ( string $json [, bool $assoc= false [, int
$depth= 512 ]] )And the "name" of the param here is appropriate to PHP's use (assoc is
not part of JSON's or JS's terminology).If you can think of a better name for the flag, then I'd be glad to use it.
The JSON spec refers to them as arrays or objects though, as does our
documentation I believe.
PHP_JSON_FORCE_OBJECT
I however have another patch for more strict encoding so I'll try to
roll this in a single update.
Scott
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
I'm too convinced of the parameter name and I don't think its something
that should be added to 5.2.9 since its a feature.Scott
5.3+ would be OK then.
As to the param name, I'm not actually changing the name, just adding
another flag.In javascript's terminology,the output is an array ...
[]
or a hash
{}
So forcing a hash for arrays is pretty much what would be wanted and I
as I comment in the request, we have a "force" option when coming FROM
json data ... json_decode ( string $json [, bool $assoc= false [, int
$depth= 512 ]] )And the "name" of the param here is appropriate to PHP's use (assoc is
not part of JSON's or JS's terminology).If you can think of a better name for the flag, then I'd be glad to use it.
The JSON spec refers to them as arrays or objects though, as does our
documentation I believe.PHP_JSON_FORCE_OBJECT
I however have another patch for more strict encoding so I'll try to
roll this in a single update.Scott
When it is in JSON, it isn't an object, but an object hash, similar,
as I understand things, to the differences between a class definition
and an instance. Or, I suppose more like an object serialization and
an object.
PHP_JSON_FORCE_OBJECT would be ideal.
Thank you.
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
I'm too convinced of the parameter name and I don't think its something
that should be added to 5.2.9 since its a feature.Scott
5.3+ would be OK then.
As to the param name, I'm not actually changing the name, just adding
another flag.In javascript's terminology,the output is an array ...
[]
or a hash
{}
So forcing a hash for arrays is pretty much what would be wanted and I
as I comment in the request, we have a "force" option when coming FROM
json data ... json_decode ( string $json [, bool $assoc= false [, int
$depth= 512 ]] )And the "name" of the param here is appropriate to PHP's use (assoc is
not part of JSON's or JS's terminology).If you can think of a better name for the flag, then I'd be glad to use it.
The JSON spec refers to them as arrays or objects though, as does our
documentation I believe.PHP_JSON_FORCE_OBJECT
I however have another patch for more strict encoding so I'll try to
roll this in a single update.Scott
First of all, this isn't a "why is this not done yet" message. Honestly.
Do you have any timeframe for this though?
Do you think it will be ready for 5.3RC1?
Thank you,
Richard Quadling.
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
I think this behavior is a bit odd too:
php -r "echo json_encode(array(0=>'test'));" // ["test"]
php -r "echo json_encode(array(1=>'test'));" // {"1":"test"}
On Tue, Mar 10, 2009 at 11:32 AM, Richard Quadling <rquadling@googlemail.com
wrote:
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
I'm too convinced of the parameter name and I don't think its something
that should be added to 5.2.9 since its a feature.Scott
5.3+ would be OK then.
As to the param name, I'm not actually changing the name, just adding
another flag.In javascript's terminology,the output is an array ...
[]
or a hash
{}
So forcing a hash for arrays is pretty much what would be wanted and I
as I comment in the request, we have a "force" option when coming FROM
json data ... json_decode ( string $json [, bool $assoc= false [, int
$depth= 512 ]] )And the "name" of the param here is appropriate to PHP's use (assoc is
not part of JSON's or JS's terminology).If you can think of a better name for the flag, then I'd be glad to use
it.The JSON spec refers to them as arrays or objects though, as does our
documentation I believe.PHP_JSON_FORCE_OBJECT
I however have another patch for more strict encoding so I'll try to
roll this in a single update.Scott
First of all, this isn't a "why is this not done yet" message. Honestly.
Do you have any timeframe for this though?
Do you think it will be ready for 5.3RC1?
Thank you,
Richard Quadling.
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
2009/3/11 Christopher Östlund christopher.oestlund@gmail.com:
I think this behavior is a bit odd too:
php -r "echo json_encode(array(0=>'test'));" // ["test"]
php -r "echo json_encode(array(1=>'test'));" // {"1":"test"}
And
php -r "echo json_encode(array(0=>'test',3=>'foo'));" // {"0":"test","3":"foo"}
So it seems that zero-base, sequential, integer indexed arrays will be
output as a JS array and any other type of array will be an object
hash. The PHP_JSON_FORCE_OBJECT (thank you Scott for the name) would
at least clarify the output for dynamically created output.
On Tue, Mar 10, 2009 at 11:32 AM, Richard Quadling <rquadling@googlemail.com
wrote:
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
2009/3/2 Scott MacVicar scott@macvicar.net:
Richard Quadling wrote:
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
I'm too convinced of the parameter name and I don't think its something
that should be added to 5.2.9 since its a feature.Scott
5.3+ would be OK then.
As to the param name, I'm not actually changing the name, just adding
another flag.In javascript's terminology,the output is an array ...
[]
or a hash
{}
So forcing a hash for arrays is pretty much what would be wanted and I
as I comment in the request, we have a "force" option when coming FROM
json data ... json_decode ( string $json [, bool $assoc= false [, int
$depth= 512 ]] )And the "name" of the param here is appropriate to PHP's use (assoc is
not part of JSON's or JS's terminology).If you can think of a better name for the flag, then I'd be glad to use
it.The JSON spec refers to them as arrays or objects though, as does our
documentation I believe.PHP_JSON_FORCE_OBJECT
I however have another patch for more strict encoding so I'll try to
roll this in a single update.Scott
First of all, this isn't a "why is this not done yet" message. Honestly.
Do you have any timeframe for this though?
Do you think it will be ready for 5.3RC1?
Thank you,
Richard Quadling.
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"--
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
I believe that this is a feature, so it would not go into 5.2, sorry.
Ilia Alshanetsky
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
Index: tests/002.phpt
RCS file: /repository/php-src/ext/json/tests/002.phpt,v
retrieving revision 1.3
diff -u -r1.3 002.phpt
--- tests/002.phpt 27 May 2008 18:16:03 -0000 1.3
+++ tests/002.phpt 2 Mar 2009 16:16:13 -0000
@@ -1,4 +1,4 @@
---TEST--
+--TEST--
json_encode()
tests
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
@@ -8,8 +8,14 @@
var_dump(json_encode(""));
var_dump(json_encode(NULL));
var_dump(json_encode(TRUE));
var_dump(json_encode(array(""=>"")));
var_dump(json_encode(array(array(1))));
+var_dump(json_encode(array());
+var_dump(json_encode(array(""=>"")), PHP_JSON_FORCE_HASH);
+var_dump(json_encode(array(array(1))),PHP_JSON_FORCE_HASH);
+var_dump(json_encode(array(),PHP_JSON_FORCE_HASH);var_dump(json_encode(1));
var_dump(json_encode("руссиш"));
@@ -23,6 +29,10 @@
string(4) "true"
string(7) "{"":""}"
string(5) "[[1]]"
+string(2) "[]"
+string(7) "{"":""}"
+string(15) "{"0":{"0":"1"}}"
+string(2) "{}"
string(1) "1"
string(38) ""\u0440\u0443\u0441\u0441\u0438\u0448""
Done--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
2009/3/2 Ilia Alshanetsky ilia@prohost.org:
I believe that this is a feature, so it would not go into 5.2, sorry.
Ilia Alshanetsky
That's OK. Just like to try these things sometimes.
Hi.
Regarding http://bugs.php.net/bug.php?id=47493, I've supplied a patch
to the unit tests too.Any chance this could get committed to 5.2+
Index: tests/002.phpt
RCS file: /repository/php-src/ext/json/tests/002.phpt,v
retrieving revision 1.3
diff -u -r1.3 002.phpt
--- tests/002.phpt 27 May 2008 18:16:03 -0000 1.3
+++ tests/002.phpt 2 Mar 2009 16:16:13 -0000
@@ -1,4 +1,4 @@
---TEST--
+--TEST--
json_encode()
tests
--SKIPIF--
<?php if (!extension_loaded("json")) print "skip"; ?>
@@ -8,8 +8,14 @@
var_dump(json_encode(""));
var_dump(json_encode(NULL));
var_dump(json_encode(TRUE));
var_dump(json_encode(array(""=>"")));
var_dump(json_encode(array(array(1))));
+var_dump(json_encode(array());
+var_dump(json_encode(array(""=>"")), PHP_JSON_FORCE_HASH);
+var_dump(json_encode(array(array(1))),PHP_JSON_FORCE_HASH);
+var_dump(json_encode(array(),PHP_JSON_FORCE_HASH);var_dump(json_encode(1));
var_dump(json_encode("руссиш"));
@@ -23,6 +29,10 @@
string(4) "true"
string(7) "{"":""}"
string(5) "[[1]]"
+string(2) "[]"
+string(7) "{"":""}"
+string(15) "{"0":{"0":"1"}}"
+string(2) "{}"
string(1) "1"
string(38) ""\u0440\u0443\u0441\u0441\u0438\u0448""
Done--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"--
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"