Skip to content

Unwanted count() exception in JsonPointer.php #66

Open
@pierluiginovatag

Description

@pierluiginovatag

Comparing two structured JSON I often get this exception:

count(): Argument #1 ($value) must be of type Countable|array, string given

raised at line 152 of file JsonPointer.php:
....

                    if (0 === ($flags & self::TOLERATE_ASSOCIATIVE_ARRAYS)) {
                        **if ($intKey > count($ref) && 0 === ($flags & self::RECURSIVE_KEY_CREATION)) {** 
                            throw new JsonPointerException('Index is greater than number of items in array');
                        } elseif ($intKey < 0) {
                            throw new JsonPointerException('Negative index');
                        }
                    }

....

I am calling jsonDiff in this way:

                    $diff = new JsonDiff(
                        $jsonTarget,
                        $jsonNew,
                        JsonDiff::REARRANGE_ARRAYS +
                            JsonDiff::COLLECT_MODIFIED_DIFF
                    );

with these two objects (first is Target, second is New), that are obviously differents:

TARGET
[["' POT NOODLE 500011820348 £0.80D'","NOODLE","",[""],"","1","DRY PASTA AND RICE"],["' STIR FRY 501033820008 £0.75D'","LETTUCE","",[""],"","1","VEGETABLES"],["' CB SOUP 500023286522 £1.00D'","VEGETABLE SOUP","",["BOTTIGLIA","1.00 L"],"","1","VEGETABLES"],["' KIDNEY BEANS 505244916778 £0.33D £1.00D'","BEANS","",[""],"1.00","1","LEGUMES"],["' GRAVY 505717209125 £0.28D'","FILLETS","",[""],"","1","MEATS READY TO BE COOKED"],["' BAKED BEANS 505244916772 £2.00D'","BEANS","",[""],"","1","LEGUMES"],["' COFFEE 844529032622'","COFFEE","",["844529032622 L"],"","1","COFFEE AND INFUSIONS"],["' CHOCOLATE 505407086455'","CHOCOLATE","",[""],"","1","CHOCOLATE AND CHOCOLATES"],["' KITCHEN ROLL 800426021048 £4.75V'","REGINA KITCHEN ROLL","REGINA",["800426021048 METRI"],"","1","HOME CARE"],["' TABLE SALT 501998910311 £0.95D'","SALT","",[""],"","1","SAUCES AND CONDIMENTS"],["' RED WINE 780432074610 £8.00V'","WINE","",["x 780432074610"],"","1","ALCOHOLIC BEVERAGES"]]

NEW
[[" PUI NUUULE £0.80D","BURGER","",[""],"","1","MEATS READY TO BE COOKED"],[" POT NOODLE 500011820348 £0.75D","NOODLE","",[""],"","1","DRY PASTA AND RICE"],[" CB SOUP 500023286522","VEGETABLE SOUP","",["BOTTIGLIA"],"","1","VEGETABLES"],[" KIDNEY BEANS 505244916778","BEANS","",[""],"","1","LEGUMES"],[" £1.00D","KIWI","",[""],"","1","FRUIT"],[" GRAVY 505717209125","FILLETS","",[""],"","1","MEATS READY TO BE COOKED"],[" BAKED BEANS","BEANS","",[""],"","1","LEGUMES"],[" 844529032622 £2.00D","KIWI","",[""],"","1","FRUIT"],[" COFFEE","COFFEE","",[""],"","1","COFFEE AND INFUSIONS"],[" CHOCOLATE 505407086455 £1.29V","CHOCOLATE","",[""],"","1","CHOCOLATE AND CHOCOLATES"],[" KITCHEN ROLL 800426021048","REGINA KITCHEN ROLL","REGINA",[""],"","1","HOME CARE"],[" TABLE SALT 501998910311 £0.95D","SALT","",[""],"","1","SAUCES AND CONDIMENTS"],[" RED WINE 780432074610 £8.00V","WINE","",["x 780432074610"],"","1","ALCOHOLIC BEVERAGES"]]

Is there a way to avoid /solve this ?

I am runnig PHO 8.1.10

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions