symfony / polyfill

PHP polyfills

Home Page:https://symfony.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for JSON_THROW_ON_ERROR for the PHP 7.3 polyfill

theofidry opened this issue · comments

If feels like it's something that could be provided by the polyfill as well. I can try to do a PR if that's ok.

Note that there is also the exception JsonException missing.

Also the doc for the PHP 7.3 polyfill is outdated, given the entry of the docs for the polyfills, maybe those could be automated somehow to keep them in sync.

How would you implement this? Just declaring the constant maybe?

If the constant is not defined then declare it yeah, or conditionally declare it based on the PHP version.

The difficulty would be to add this functionality to the json_decode function. As just adding the exception and the constant won't create the same functionality.

no indeed you would also need to override the json_decode()/json_encode() functions and check for the mode to thrown an error when the option is passed down

we cannot override functions, as they are already declared.

damnit, indeed it's not new functions so that won't work :/ Well I'll be closing it then I guess

Actually this could easily be done using PHP's native "use function"

http://php.net/manual/en/language.namespaces.importing.php

Examples: https://laravel-news.com/php-safe

@tm1000 it's a new function in a new namespace, it's not a polyfill for the existing native PHP function