From 7d957752beac420cfc0852f8b3d29f561b217e91 Mon Sep 17 00:00:00 2001 From: jorgecc Date: Sat, 6 Apr 2024 12:37:23 -0300 Subject: [PATCH] 2.4 --- README.md | 2 ++ composer.json | 2 +- src/Services_JSON.php | 34 +++++++++++++++++++--------------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 8302a55..036fd88 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ var_dump(Services_JSON::encode($obj)); // encode an object ## Changelog +* 2.4 + * update requirements to php 7.4 * 2.3.2 * Added flag to decode() DECODE_NO_QUOTE * 2.3.1 diff --git a/composer.json b/composer.json index da5b87c..c9454a9 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } ], "require": { - "php": ">=7.2.5" + "php": ">=7.4" }, "suggest": { "ext-mbstring": "*" diff --git a/src/Services_JSON.php b/src/Services_JSON.php index ddd9c82..c75901d 100644 --- a/src/Services_JSON.php +++ b/src/Services_JSON.php @@ -1,4 +1,5 @@ - * @access public */ - public static function decode($str, int $use = 0) + public static function decode(string $str, int $use = 0) { if ($use & self::DECODE_FIX_ROOT) { $str = trim($str); + if($str==="") { + throw new RuntimeException("no value to decode"); + } $firstChar = $str[0]; if ($firstChar !== '{' && $firstChar !== '[') { // fixing a malformed json-u, if the json-u doesn't start with { [ and ends with ] } then it wraps it @@ -734,7 +738,7 @@ class Services_JSON * @param string $str * @return integer length */ - protected static function strlen8($str): int + protected static function strlen8(string $str): int { if (self::$_mb_strlen) { return mb_strlen($str, "8bit"); @@ -746,10 +750,10 @@ class Services_JSON * Returns part of a string, interpreting $start and $length as number of bytes. * @param string $string * @param integer $start start - * @param integer $length length + * @param integer|bool $length length * @return string length */ - protected static function substr8($string, $start, $length = false): string + protected static function substr8(string $string, int $start, $length = false): string { if ($length === false) { $length = self::strlen8($string) - $start;