zendframework / zf1

This project reached its end-of-life on 2016-09-28. Contains conversion of ZF1 subversion repo to git, from version 15234 forward, and only containing master and release-1.12 branches and 1.12 tags.
https://framework.zend.com/blog/2016-06-28-zf1-eol.html
BSD 3-Clause "New" or "Revised" License
357 stars 801 forks source link

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

Closed v-noskov closed 8 years ago

v-noskov commented 8 years ago

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 commented 8 years ago

Fixed by #680

yuripave commented 8 years ago

@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 https://github.com/zendframework/zend-json/issues/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 commented 8 years ago

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 commented 8 years ago

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

akrabat commented 8 years ago

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