$option ]); if ($result === false && $data !== serialize(false)) { throw new RuntimeException( 'Invalid serialized data or potential security risk.' ); } return $result; } catch (RuntimeException $e) { throw $e; } finally { restore_error_handler(); } } throw new RuntimeException( 'Invalid data format: Neither JSON nor serialized PHP data.' ); } /** * Check if the data is a valid JSON string. * * @param string $data Data to check. * @return bool True if the data is valid JSON. */ public static function isJson($data) { json_decode($data); return (json_last_error() === JSON_ERROR_NONE); } /** * Check if the data is a serialized PHP string. * * @param string $data Data to check. * @return bool True if the data is serialized. */ public static function isSerialized($data) { return is_serialized($data); } }