colinodell/json5

Function signature not fully compatible with json_decode

aste-mikkok opened this issue · 1 comments

This package adds a json5_decode() function which is a drop-in replacement for PHP's built-in json_decode():

$json = file_get_contents('foo.json5');
$data = json5_decode($json);

It takes the same exact parameters in the same order. For more details on these, see the PHP docs.

"It takes the same exact parameters in the same order" is not entirely true, as the flags parameter of json_decode has been renamed to options. Thus you can use named parameters and call json_decode($payload, flags: JSON_THROW_ON_ERROR) but calling json5_decode($payload, flags: JSON_THROW_ON_ERROR) will throw an exception.

I realize this a minor difference and debated whether to even post the issue, but named parameters is a legit use case so I will just leave it up to the maintainer to decide.

Edit: And i suppose there is a similar issue with the first parameter being named source instead of json.

Wow, good catch, I'm not sure how I missed that before. I agree that we should rename this parameter even if it does require a new major version release. I'll try to get this done in the next few days.

Thanks for bringing this to my attention!