3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * This code should loop through $data, converting null to 0. * * If it finds an array inside the data, it loops through that * converting null values to 0. * * The error'ed line throws the following PHP error which breaks the code: * ------- * PHP Warning: Cannot use a scalar value as an array * ------- */ $data = json_decode('{"last":"0.692776960","high":"0.692776960","low":"0.692776960","avg":0.6928,"vol":"0.252273837","vols":{"bid":null,"ask":null}}', 1); $new_data = []; foreach($data as $outer_key=>$outer_value) { var_dump($new_data); if(is_array($outer_value)) { $new_key = (string) $outer_key; // ERROR LINE START $new_data[$new_key] = []; // ERROR LINE END foreach($outer_value as $inner_key=>$inner_value) { Log::info("k is " . json_encode($outer_key) . "v is " . json_encode($outer_value) . " p is " . json_encode($inner_key) . " and z is " . json_encode($inner_value) . ""); $new_data[$new_key][$inner_key] = ($inner_value !== null) ?: 0; } } else { $new_data = ($data !== null) ?: 0; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 58
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 58
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 53
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 51
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 51
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 51
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
filename:       /in/VqhU3
function name:  (null)
number of ops:  60
compiled vars:  !0 = $data, !1 = $new_data, !2 = $outer_value, !3 = $outer_key, !4 = $new_key, !5 = $inner_value, !6 = $inner_key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%7B%22last%22%3A%220.692776960%22%2C%22high%22%3A%220.692776960%22%2C%22low%22%3A%220.692776960%22%2C%22avg%22%3A0.6928%2C%22vol%22%3A%220.252273837%22%2C%22vols%22%3A%7B%22bid%22%3Anull%2C%22ask%22%3Anull%7D%7D'
          2        SEND_VAL                                                 1
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !0, $7
   14     5        ASSIGN                                                   !1, <array>
   15     6      > FE_RESET_R                                       $10     !0, ->58
          7    > > FE_FETCH_R                                       ~11     $10, !2, ->58
          8    >   ASSIGN                                                   !3, ~11
   16     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
   17    12        TYPE_CHECK                                  128          !2
         13      > JMPZ                                                     ~14, ->53
   18    14    >   CAST                                          6  ~15     !3
         15        ASSIGN                                                   !4, ~15
   20    16        ASSIGN_DIM                                               !1, !4
         17        OP_DATA                                                  <array>
   22    18      > FE_RESET_R                                       $18     !2, ->51
         19    > > FE_FETCH_R                                       ~19     $18, !5, ->51
         20    >   ASSIGN                                                   !6, ~19
   23    21        INIT_STATIC_METHOD_CALL                                  'Log', 'info'
         22        INIT_FCALL                                               'json_encode'
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                         $21     
         25        CONCAT                                           ~22     'k+is+', $21
         26        CONCAT                                           ~23     ~22, 'v+is+'
         27        INIT_FCALL                                               'json_encode'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                         $24     
         30        CONCAT                                           ~25     ~23, $24
         31        CONCAT                                           ~26     ~25, '+p+is+'
         32        INIT_FCALL                                               'json_encode'
         33        SEND_VAR                                                 !6
         34        DO_ICALL                                         $27     
         35        CONCAT                                           ~28     ~26, $27
         36        CONCAT                                           ~29     ~28, '+and+z+is+'
         37        INIT_FCALL                                               'json_encode'
         38        SEND_VAR                                                 !5
         39        DO_ICALL                                         $30     
         40        CONCAT                                           ~31     ~29, $30
         41        CONCAT                                           ~32     ~31, ''
         42        SEND_VAL_EX                                              ~32
         43        DO_FCALL                                      0          
   24    44        TYPE_CHECK                                  1020  ~36     !5
         45        JMP_SET                                          ~37     ~36, ->47
         46        QM_ASSIGN                                        ~37     0
         47        FETCH_DIM_W                                      $34     !1, !4
         48        ASSIGN_DIM                                               $34, !6
         49        OP_DATA                                                  ~37
   22    50      > JMP                                                      ->19
         51    >   FE_FREE                                                  $18
         52      > JMP                                                      ->57
   27    53    >   TYPE_CHECK                                  1020  ~38     !0
         54        JMP_SET                                          ~39     ~38, ->56
         55        QM_ASSIGN                                        ~39     0
         56        ASSIGN                                                   !1, ~39
   15    57    > > JMP                                                      ->7
         58    >   FE_FREE                                                  $10
   29    59      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.53 ms | 1405 KiB | 19 Q