3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[ {"recipient_name":"John D", "phone_number":"123456"}, {"recipient_name":"Doe J", "phone_number":"654321"}, {"recipient_name":"Jon Do", "phone_number":"112233"} ]'; $myLargerArray = json_decode($json, true); $myObjArray = (object)['message_recipients' => array()]; $size = count($myLargerArray); for( $j = 0; $j < $size; $j++ ) { $myRecipientsObj->recipient_name = $myLargerArray[$j]['recipient_name']; $myRecipientsObj->phone_number = $myLargerArray[$j]['phone_number']; // var_dump($myRecipientsObj); // This outputs the correct data added from [$j] array_push($myObjArray->message_recipients, clone $myRecipientsObj); var_dump($myObjArray->message_recipients); // The output shows array elements are being overwritten at each loop iteration }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
Branch analysis from position: 12
filename:       /in/UcITu
function name:  (null)
number of ops:  34
compiled vars:  !0 = $json, !1 = $myLargerArray, !2 = $myObjArray, !3 = $size, !4 = $j, !5 = $myRecipientsObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A++++%7B%22recipient_name%22%3A%22John+D%22%2C+%22phone_number%22%3A%22123456%22%7D%2C%0A++++%7B%22recipient_name%22%3A%22Doe+J%22%2C+%22phone_number%22%3A%22654321%22%7D%2C%0A++++%7B%22recipient_name%22%3A%22Jon+Do%22%2C+%22phone_number%22%3A%22112233%22%7D%0A%5D'
    8     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
    9     6        CAST                                          8  ~9      <array>
          7        ASSIGN                                                   !2, ~9
   10     8        COUNT                                            ~11     !1
          9        ASSIGN                                                   !3, ~11
   11    10        ASSIGN                                                   !4, 0
         11      > JMP                                                      ->31
   12    12    >   FETCH_DIM_R                                      ~15     !1, !4
         13        FETCH_DIM_R                                      ~16     ~15, 'recipient_name'
         14        ASSIGN_OBJ                                               !5, 'recipient_name'
         15        OP_DATA                                                  ~16
   13    16        FETCH_DIM_R                                      ~18     !1, !4
         17        FETCH_DIM_R                                      ~19     ~18, 'phone_number'
         18        ASSIGN_OBJ                                               !5, 'phone_number'
         19        OP_DATA                                                  ~19
   17    20        INIT_FCALL                                               'array_push'
         21        FETCH_OBJ_W                                      $20     !2, 'message_recipients'
         22        SEND_REF                                                 $20
         23        CLONE                                            ~21     !5
         24        SEND_VAL                                                 ~21
         25        DO_ICALL                                                 
   19    26        INIT_FCALL                                               'var_dump'
         27        FETCH_OBJ_R                                      ~23     !2, 'message_recipients'
         28        SEND_VAL                                                 ~23
         29        DO_ICALL                                                 
   11    30        PRE_INC                                                  !4
         31    >   IS_SMALLER                                               !4, !3
         32      > JMPNZ                                                    ~26, ->12
   20    33    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.72 ms | 1400 KiB | 20 Q