We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The PHP C extension implementation native PHP implementation have different behavior when deserializing a empty JSON object/array.
The native php implementation threats both '{}' and [] as valid inputs. And the C extension allow only {} (I believe that is the correct behaviour)
[]
{}
This happens BC In php the function json_encode will encode a empty associative array as []
json_encode
php -r "var_dump(json_encode(array_filter(['foo' => null])));" string(2) "[]"
And we also get back the same php value when decoding both {} and []:
$php -r "var_dump(json_decode('[]', true, 512, JSON_BIGINT_AS_STRING));" array(0) { } $ php -r "var_dump(json_decode('{}', true, 512, JSON_BIGINT_AS_STRING));" array(0) { }
PHP Implementation :
protobuf/php/src/Google/Protobuf/Internal/Message.php
Line 1324 in e3ac4c9
What version of protobuf and what language are you using? Version: main Language: php OS: Linux
What did you do?
<?php require_once (dirname(__DIR__) . '/vendor/autoload.php'); require_once (__DIR__ . '/test_util.php'); use Foo\TestMessage; $message = new TestMessage(); $values = array_filter([ 'true_optional_string' => null, ]); $message->mergeFromJsonString(json_encode($values)); //$message->mergeFromJsonString('[]'); var_dump($message->hasTrueOptionalString());
#### Compile the extension ./php/tests/compile_extension.sh # Run script php -d display_errors=on -dextension=../ext/google/protobuf/modules/protobuf.so json_encode_test.php
What did you expect to see ?
Error parsing JSON
What did you see instead? C extension:
Fatal error: Uncaught Exception: Error occurred during parsing: Error parsing JSON @1:0: Expected: '{'
PHP implementation:
bool(false)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The PHP C extension implementation native PHP implementation have different behavior when deserializing a empty JSON object/array.
The native php implementation threats both '{}' and
[]
as valid inputs.And the C extension allow only
{}
(I believe that is the correct behaviour)This happens BC In php the function
json_encode
will encode a empty associative array as[]
And we also get back the same php value when decoding both
{}
and[]
:PHP Implementation :
protobuf/php/src/Google/Protobuf/Internal/Message.php
Line 1324 in e3ac4c9
What version of protobuf and what language are you using?
Version: main
Language: php
OS: Linux
What did you do?
What did you expect to see ?
What did you see instead?
C extension:
PHP implementation:
The text was updated successfully, but these errors were encountered: