Skip to content

Instantly share code, notes, and snippets.

@gongo
Last active October 2, 2015 05:49
Show Gist options
  • Save gongo/d0252cdc74dfad1fc8fb to your computer and use it in GitHub Desktop.
Save gongo/d0252cdc74dfad1fc8fb to your computer and use it in GitHub Desktop.

PHP: PHP 5.5.x から PHP 5.6.x への移行 - 下位互換性のない変更点 - Manual を見ると

json_decode() は、JSON リテラル true、false および null について、 すべて小文字のものしか受け付けなくなりました。 これは、JSON の仕様に基づくものです。 小文字以外の場合は、json_last_error() にエラーが設定されます。 以前のバージョンの json_decode() は、大文字が混ざっているものでも受け付けていました。

とあるので、試してみたが、PHP 5.6 でも TRUE とか NULL で通ってしまった。何か勘違いしてる?

<?php
$json = <<<'EOS'
{
"a": true,
"b": TRUE,
"c": false,
"d": FALSE,
"e": null,
"f": NULL
}
EOS;
var_dump(
PHP_VERSION,
json_decode($json),
json_last_error() == JSON_ERROR_NONE
);
// $ php foo.php
// string(6) "5.6.14"
// class stdClass#1 (6) {
// public $a =>
// bool(true)
// public $b =>
// bool(true)
// public $c =>
// bool(false)
// public $d =>
// bool(false)
// public $e =>
// NULL
// public $f =>
// NULL
// }
// bool(true)
@gongo
Copy link
Author

gongo commented Oct 2, 2015

解決しました。remi の PHP 5.6 を使ってたからです

つまり remi リポジトリの PHP 5.6 を使っている場合、

json_decode() は、JSON リテラル true、false および null について、すべて小文字のものしか受け付けなくなりました。

というのは関係ない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment