Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/JsonPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,10 @@ private static function do_op($doc, $op, $path, $parts, $value,
return $doc;
}

if (null === $doc && ($op == 'add' || $op == 'append')) {
$doc = [];
}

// at target
if (!is_array($doc))
{
Expand All @@ -534,8 +538,7 @@ private static function do_op($doc, $op, $path, $parts, $value,
{
// check range, if numeric
if (self::is_index($part) &&
($part < 0 || (($op == 'remove' && $part >= count($doc))
|| ($op != 'remove' && $part > count($doc)))))
($part < 0 || (($op == 'remove' && $part >= count($doc)))))
{
throw new JsonPatchException("Can't operate outside of array bounds");
}
Expand Down