Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Zend_Json::decode null or empty string throw Zend_Json_Exception on PHP7 #678

Closed
v-noskov opened this issue Mar 16, 2016 · 5 comments
Closed

Comments

@v-noskov
Copy link

I have the following code that works on php 5.6 but throws Zend_Json_Exception on PHP7.

Zend_Json::decode(null);
Zend_Json::decode('');

Each call causes Zend_Json_Exception.

Zend_Json_Exception: Decoding failed: Syntax error

This bug caused by https://bugs.php.net/bug.php?id=71718
Code:

Zend_Json::$useBuiltinEncoderDecoder = true;
Zend_Json::decode(null);
Zend_Json::decode('');

runs without exceptions.

@v-noskov
Copy link
Author

Fixed by #680

@yuripave
Copy link

yuripave commented Apr 16, 2016

@v-noskov @weierophinney We need to decide whether we should fixed this in Zend_Json or not.
Fixing it will make it behaves the same as PHP5 but null or empty string is indeed not a valid json and it is intended behavior on PHP7. See discussion on zendframework/zend-json#23. Whatever the final decision we should make Zend_Json and ZF2 zend-json behaves the same.

References:
https://bugs.php.net/bug.php?id=71718
http://php.net/manual/en/function.json-last-error.php#118165
http://stackoverflow.com/questions/36362856/php7-json-and-zend-decoding-failed-syntax-error

@v-noskov
Copy link
Author

I think, that Zend_Json v.1.12.xx must preserve backward compatibility and demonstrate the same behaviour on all supported versions of php. Also, ZF2 components can have other behaviour than ZF1 components.

@froschdesign
Copy link
Member

@v-noskov
ZF1 has no official support for PHP 7.

@akrabat
Copy link
Contributor

akrabat commented Apr 20, 2016

This is a change to the underlying PHP method, not a bug in Zend\Json.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants