Skip to content

'Swaggest\\JsonDiff\\Exception' with message 'Key not found: key'  #9

Closed
@allentsai

Description

@allentsai

Hello, I'm getting the following error:

Exception/Stack Trace:

PHP Fatal error:  Uncaught exception 'Swaggest\\JsonDiff\\Exception' with message 
'Invalid key for array operation' in /usr/local/src/placelocal/vendor/swaggest/json-diff/src/JsonPointer.php:120
Stack trace:
#0 /usr/local/src/placelocal/vendor/swaggest/json-diff/src/JsonPatch.php(121): Swaggest\\JsonDiff\\JsonPointer::add(Object(stdClass), Array, 'missing value', false)
#1 /usr/local/src/placelocal/public_html/test.php(34): Swaggest\\JsonDiff\\JsonPatch->apply(Object(stdClass))
#2 {main}
  thrown in /usr/local/src/placelocal/vendor/swaggest/json-diff/src/JsonPointer.php on line 120

Using php5.6, v3.4.0

Test Code:

$old = [
    "key" => "diffvalue",
    "nestedKey" => ["nestedKey" => "nesteddiffValue"],
    "unchanged" => "value",
    "new key" => "new value",
    "new array" => ["new value3", "new value2"],
    "notMissingKey" => [],
    "appendKey" => ["value1", "value2"]
];
$new = [
    "key" => "value",
    "nestedKey" => ["nestedKey2" => "nestedValue"],
    "unchanged" => "value",
    "missingKey" => ["missingkey's child key" => "missing value"],
    "notMissingKey" => ["nmk:missingkey" => "missing value", "nmk:missingkey2" => "missing value 2"],
    "appendKey" => ["value1"]
];

$diff = new \Swaggest\JsonDiff\JsonDiff(json_decode(json_encode($old)), json_decode(json_encode($new)));
$patch = $diff->getPatch();

$test = json_decode(json_encode($old));
$patch->apply($test);

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