@@ -306,7 +306,6 @@ private function process($original, $new)
306
306
307
307
$ originalKeys = $ original instanceof \stdClass ? get_object_vars ($ original ) : $ original ;
308
308
$ isArray = is_array ($ original );
309
- $ removedOffset = 0 ;
310
309
311
310
if ($ merge && is_array ($ new ) && !is_array ($ original )) {
312
311
$ merge = false ;
@@ -318,6 +317,9 @@ private function process($original, $new)
318
317
319
318
$ isUriFragment = (bool )($ this ->options & self ::JSON_URI_FRAGMENT_ID );
320
319
$ diffCnt = $ this ->addedCnt + $ this ->modifiedCnt + $ this ->removedCnt ;
320
+ if ($ isArray ) {
321
+ $ originalKeys = array_reverse ($ originalKeys , true );
322
+ }
321
323
foreach ($ originalKeys as $ key => $ originalValue ) {
322
324
if ($ this ->options & self ::STOP_ON_DIFF ) {
323
325
if ($ this ->modifiedCnt || $ this ->addedCnt || $ this ->removedCnt ) {
@@ -327,12 +329,8 @@ private function process($original, $new)
327
329
328
330
$ path = $ this ->path ;
329
331
$ pathItems = $ this ->pathItems ;
330
- $ actualKey = $ key ;
331
- if ($ isArray && is_int ($ actualKey )) {
332
- $ actualKey -= $ removedOffset ;
333
- }
334
- $ this ->path .= '/ ' . JsonPointer::escapeSegment ((string )$ actualKey , $ isUriFragment );
335
- $ this ->pathItems [] = $ actualKey ;
332
+ $ this ->path .= '/ ' . JsonPointer::escapeSegment ((string )$ key , $ isUriFragment );
333
+ $ this ->pathItems [] = $ key ;
336
334
337
335
if (array_key_exists ($ key , $ newArray )) {
338
336
$ newOrdered [$ key ] = $ this ->process ($ originalValue , $ newArray [$ key ]);
@@ -343,9 +341,6 @@ private function process($original, $new)
343
341
return null ;
344
342
}
345
343
$ this ->removedPaths [] = $ this ->path ;
346
- if ($ isArray ) {
347
- $ removedOffset ++;
348
- }
349
344
350
345
if ($ this ->jsonPatch !== null ) {
351
346
$ this ->jsonPatch ->op (new Remove ($ this ->path ));
0 commit comments