65536) { throw new InvalidArgumentException('payload_too_large'); } try { $settings = json_decode($json, false, 64, JSON_THROW_ON_ERROR); } catch (JsonException) { throw new InvalidArgumentException('invalid_json'); } if (!$settings instanceof stdClass || !is_bool($settings->enabled ?? null)) { throw new InvalidArgumentException('invalid_settings'); } return $settings->enabled; } foreach (['{"enabled":false}', '{"enabled":"false"}', 'null', '[]', '{'] as $input) { try { echo readEnabled($input) ? "enabled\n" : "disabled\n"; } catch (InvalidArgumentException $error) { echo $error->getMessage(), PHP_EOL; } }