json-patch-php icon indicating copy to clipboard operation
json-patch-php copied to clipboard

count(): Parameter must be an array or an object that implements Countable

Open 4n70w4 opened this issue 6 years ago • 3 comments

src:

{"bankruptcy":null}

$src = {array} [1]
 bankruptcy = null

dst:

{"bankruptcy":24}

$dst = {array} [1]
 bankruptcy = {int} 24
{
    "message": "count(): Parameter must be an array or an object that implements Countable",
    "exception": "ErrorException",
    "file": "/var/www/app/vendor/mikemccabe/json-patch-php/src/JsonPatch.php",
    "line": 264,
    "trace": [
        {
            "file": "/var/www/app/vendor/sentry/sentry/src/ErrorHandler.php",
            "line": 361,
            "function": "handleError",
            "class": "Illuminate\\Foundation\\Bootstrap\\HandleExceptions",
            "type": "->"
        },
        {
            "function": "handleError",
            "class": "Sentry\\ErrorHandler",
            "type": "->"
        },
        {
            "file": "/var/www/app/vendor/mikemccabe/json-patch-php/src/JsonPatch.php",
            "line": 264,
            "function": "count"
        },
        {
            "file": "/var/www/app/vendor/mikemccabe/json-patch-php/src/JsonPatch.php",
            "line": 311,
            "function": "diff_values",
            "class": "mikemccabe\\JsonPatch\\JsonPatch",
            "type": "::"
        },
        {
            "file": "/var/www/app/vendor/mikemccabe/json-patch-php/src/JsonPatch.php",
            "line": 271,
            "function": "diff_assoc",
            "class": "mikemccabe\\JsonPatch\\JsonPatch",
            "type": "::"
        },
        {
            "file": "/var/www/app/vendor/mikemccabe/json-patch-php/src/JsonPatch.php",
            "line": 77,
            "function": "diff_values",
            "class": "mikemccabe\\JsonPatch\\JsonPatch",
            "type": "::"
        },

4n70w4 avatar Sep 25 '19 16:09 4n70w4

Workaround:

Index: vendor/mikemccabe/json-patch-php/src/JsonPatch.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vendor/mikemccabe/json-patch-php/src/JsonPatch.php	(date 1569430634786)
+++ vendor/mikemccabe/json-patch-php/src/JsonPatch.php	(date 1569430634786)
@@ -261,7 +261,7 @@
   private static function diff_values($path, $value, $other)
   {
     // manually handle the {}-looks-like-[] case, when other is associative
-    if ((count($value) == 0 || count($other) == 0)
+    if ((@count($value) == 0 || @count($other) == 0)
         && (self::is_associative($value) || self::is_associative($other)))
     {
       return self::diff_assoc($path, $value, $other);

4n70w4 avatar Sep 25 '19 16:09 4n70w4

or require dev-master version

4n70w4 avatar Sep 26 '19 12:09 4n70w4

And another patch:

Idex: vendor/mikemccabe/json-patch-php/src/JsonPatch.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vendor/mikemccabe/json-patch-php/src/JsonPatch.php	(date 1570547451959)
+++ vendor/mikemccabe/json-patch-php/src/JsonPatch.php	(date 1570547451959)
@@ -291,7 +291,7 @@
   private static function diff_assoc($path, $src, $dst)
   {
     $result = array();
-    if (count($src) == 0 && count($dst) != 0)
+    if (@count($src) == 0 && @count($dst) != 0)
     {
       $result[] = array("op" => "replace", "path" => "$path", "value" => $dst);
     }

4n70w4 avatar Oct 08 '19 15:10 4n70w4