From e0e0d9cd3614125d345cad2fbea04c68de308871 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Sun, 19 Jun 2022 23:14:08 +0200 Subject: [PATCH 1/3] Type check first parameter for Json::stringToObject() --- composer.json | 1 + src/Format/Json.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/composer.json b/composer.json index e756bd51..25d133b7 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "symfony/yaml": "<3.4" }, "suggest": { + "ext-json": "ext-json is needed for JSON support", "symfony/yaml": "Install symfony/yaml if you require YAML support." }, "autoload": { diff --git a/src/Format/Json.php b/src/Format/Json.php index b76d3a74..621866f2 100644 --- a/src/Format/Json.php +++ b/src/Format/Json.php @@ -51,6 +51,19 @@ public function objectToString($object, array $options = []) */ public function stringToObject($data, array $options = ['processSections' => false]) { + if (!is_string($data)) + { + trigger_error( + sprintf( + 'Passing non-string values as first parameter to %s is deprecated and will cause an error in 3.0', + __METHOD__ + ), + E_USER_DEPRECATED + ); + + $data = (string) $data; + } + $data = trim($data); // Because developers are clearly not validating their data before pushing it into a Registry, we'll do it for them From a4c1582f9060099b4e573721b0cc4e5d0ed895ed Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Wed, 6 Jul 2022 19:39:30 +0200 Subject: [PATCH 2/3] Fix CS issues --- src/Format/Json.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Format/Json.php b/src/Format/Json.php index 09dce231..dabf2489 100644 --- a/src/Format/Json.php +++ b/src/Format/Json.php @@ -52,10 +52,9 @@ public function objectToString($object, array $options = []) */ public function stringToObject($data, array $options = ['processSections' => false]) { - if (!is_string($data)) - { - trigger_error( - sprintf( + if (!\is_string($data)) { + \trigger_error( + \sprintf( 'Passing non-string values as first parameter to %s is deprecated and will cause an error in 3.0', __METHOD__ ), From 59a5f2287c35f6e7a7049d7e20a40cf1660a25cf Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Wed, 6 Jul 2022 19:48:12 +0200 Subject: [PATCH 3/3] Add @since tag to document changes --- src/Format/Json.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Format/Json.php b/src/Format/Json.php index dabf2489..b1464d69 100644 --- a/src/Format/Json.php +++ b/src/Format/Json.php @@ -49,6 +49,8 @@ public function objectToString($object, array $options = []) * * @throws \RuntimeException * @since 1.0.0 + * @since __DEPLOY_VERSION__ Passing non-string values as first parameter is deprecated and will issue an + * E_USER_DEPRECATED warning. It will cause an error in 3.0. */ public function stringToObject($data, array $options = ['processSections' => false]) {