-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Here is the code:
<?php
error_reporting(E_ALL);
require_once __DIR__ . "/../vendor/autoload.php";
use mikemccabe\JsonPatch\JsonPatch;
$src = [
'a' => 'value a',
'd' => [
'klm'
]
];
$dst = [
'b' => 'value b',
'c' => [
],
'd' => [
'abc', 'efg', 'klm'
]
];
// get the A to B difference
$patch = JsonPatch::diff($src, $dst);
echo '<pre>' . var_export($patch, true) . '</pre><br>';
// make B from A using the difference
$original = JsonPatch::patch($src, $patch);
echo '<pre>' . var_export($original, true) . '</pre><br>';
?>
The second test fails with following error:
Fatal error: Uncaught mikemccabe\JsonPatch\JsonPatchException: Can't operate outside of array bounds in C:\xampp\htdocs\web\vendor\mikemccabe\json-patch-php\src\JsonPatch.php:540 Stack trace: #0 C:\xampp\htdocs\web\vendor\mikemccabe\json-patch-php\src\JsonPatch.php(514): mikemccabe\JsonPatch\JsonPatch::do_op(Array, 'add', '/d/2', Array, 'klm', false) #1 C:\xampp\htdocs\web\vendor\mikemccabe\json-patch-php\src\JsonPatch.php(135): mikemccabe\JsonPatch\JsonPatch::do_op(Array, 'add', '/d/2', Array, 'klm', false) #2 C:\xampp\htdocs\web\tests\test_json_patch.php(30): mikemccabe\JsonPatch\JsonPatch::patch(Array, Array) #3 {main} thrown in C:\xampp\htdocs\web\vendor\mikemccabe\json-patch-php\src\JsonPatch.php on line 540
On top of errors - a year ago PHP7 was released, but no optimisations done since that time to the branch, so is the project dead now?
If the problem from above is fixed then this project is usable :)
Bu I am still having issues understanding - what
JsonPatch::get($doc, $pointer) - get a value from a json document
is for? What is the pointer and what is the example of using it?