note 129228 added to function.json-validate

From: Date: Thu, 08 Feb 2024 14:18:40 +0000
Subject: note 129228 added to function.json-validate
Groups: php.notes 
Request: Send a blank email to php-notes+get-221182@lists.php.net to get a copy of this message
Pre PHP 8.3, and future compatible, function/wrapper --- if(!function_exists("json_validate")) { function json_validate() { try { json_decode($json, JSON_THROW_ON_ERROR); return true; } catch(\JsonException) { return false; } } } --- An issue with simply relying on json_last_error() == JSON_ERROR_NONE is if you have an error handler that catches errors or notices and throws them instead as fx. \ErrorException That would cause a call to json_decode(); to throw an exception exiting the scope of the function. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.131 (proxied: 152.115.151.122) ---- Manual Page -- https://php.net/manual/en/function.json-validate.php Edit -- https://main.php.net/note/edit/129228 Del: integrated -- https://main.php.net/note/delete/129228/integrated Del: useless -- https://main.php.net/note/delete/129228/useless Del: bad code -- https://main.php.net/note/delete/129228/bad+code Del: spam -- https://main.php.net/note/delete/129228/spam Del: non-english -- https://main.php.net/note/delete/129228/non-english Del: in docs -- https://main.php.net/note/delete/129228/in+docs Del: other reasons-- https://main.php.net/note/delete/129228 Reject -- https://main.php.net/note/reject/129228 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221182) next »