3v4l.org

run code in 300+ PHP versions simultaneously
<?php $context = [ 'mes' => [ 'attributes' => [ 't' => 'AddEvent', 'id' => 'test_id', ], 'ev' => [ 'attributes' => [ 'evt' => 'packet20130828ki3si0', 'src' => 'NVV', 'st' => 'test', 'start' => '12423511247', 'stop' => '12423991978', 'addrtype' => 'MB', 'clntID' => '+380957700418', 'lg' => '', 'bank' => '', 'lang' => '', 'prior' => '', 'brnm' => '', 'extref' => '', 'intref' => '', 'extaddrtype' => '', 'extaddrid' => '', 'recall' => '', ], 'attr' => [ [ 'attributes' => [ 'code' => '1', 'val' => '11', ], ], [ 'attributes' => [ 'code' => '2', 'val' => '12', ], ], ], 'hist' => [ [ 'attributes' => [ 'st' => '', 'ch' => '', 'lg' => '', 'con' => '', 'com' => '', 'addrtype' => '', 'addrid' => '', 'dt' => '', 'contactId' => '', ], ], ], ], ], ]; class Conv { protected $res; protected $context; public function __construct(array $context) { if (count($context) != 1) { throw new Exception('Must be only one root element', 500); } $this->context = $context; $this->init(key($this->context)); } public function conv() { return $this->a2x(current($this->context), $this->res)->asXML(); } protected function init($root) { $this->res = new SimpleXMLElement("<{$root}/>"); } protected function a2x(array $inner, SimpleXMLElement $node) { foreach ($inner as $key => $value) { if ($key == 'attributes') { if (count($value)) { foreach ($value as $attrKey => $attrVal) { //var_dump($attrKey, $attrVal);exit; $node->addAttribute($attrKey, $attrVal); } } } else { $subNode = $node->addChild($key); $this->a2x($value, $subNode); } } return $this->res; } } $a2x = new Conv($context); echo $a2x->conv()->asXML();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cRjTt
function name:  (null)
number of ops:  11
compiled vars:  !0 = $context, !1 = $a2x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
  104     1        NEW                                              $3      'Conv'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
  105     5        INIT_METHOD_CALL                                         !1, 'conv'
          6        DO_FCALL                                      0  $6      
          7        INIT_METHOD_CALL                                         $6, 'asXML'
          8        DO_FCALL                                      0  $7      
          9        ECHO                                                     $7
         10      > RETURN                                                   1

Class Conv:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cRjTt
function name:  __construct
number of ops:  19
compiled vars:  !0 = $context
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
   69     1        COUNT                                            ~1      !0
          2        IS_NOT_EQUAL                                             ~1, 1
          3      > JMPZ                                                     ~2, ->9
   70     4    >   NEW                                              $3      'Exception'
          5        SEND_VAL_EX                                              'Must+be+only+one+root+element'
          6        SEND_VAL_EX                                              500
          7        DO_FCALL                                      0          
          8      > THROW                                         0          $3
   72     9    >   ASSIGN_OBJ                                               'context'
         10        OP_DATA                                                  !0
   73    11        INIT_METHOD_CALL                                         'init'
         12        INIT_FCALL                                               'key'
         13        FETCH_OBJ_R                                      ~6      'context'
         14        SEND_VAL                                                 ~6
         15        DO_ICALL                                         $7      
         16        SEND_VAR_NO_REF_EX                                       $7
         17        DO_FCALL                                      0          
   74    18      > RETURN                                                   null

End of function __construct

Function conv:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cRjTt
function name:  conv
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   77     0  E >   INIT_METHOD_CALL                                         'a2x'
          1        INIT_FCALL                                               'current'
          2        FETCH_OBJ_R                                      ~0      'context'
          3        SEND_VAL                                                 ~0
          4        DO_ICALL                                         $1      
          5        SEND_VAR_NO_REF_EX                                       $1
          6        CHECK_FUNC_ARG                                           
          7        FETCH_OBJ_FUNC_ARG                               $2      'res'
          8        SEND_FUNC_ARG                                            $2
          9        DO_FCALL                                      0  $3      
         10        INIT_METHOD_CALL                                         $3, 'asXML'
         11        DO_FCALL                                      0  $4      
         12      > RETURN                                                   $4
   78    13*     > RETURN                                                   null

End of function conv

Function init:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cRjTt
function name:  init
number of ops:  10
compiled vars:  !0 = $root
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   RECV                                             !0      
   81     1        NEW                                              $2      'SimpleXMLElement'
          2        ROPE_INIT                                     3  ~4      '%3C'
          3        ROPE_ADD                                      1  ~4      ~4, !0
          4        ROPE_END                                      2  ~3      ~4, '%2F%3E'
          5        SEND_VAL_EX                                              ~3
          6        DO_FCALL                                      0          
          7        ASSIGN_OBJ                                               'res'
          8        OP_DATA                                                  $2
   82     9      > RETURN                                                   null

End of function init

Function a2x:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
Branch analysis from position: 18
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/cRjTt
function name:  a2x
number of ops:  32
compiled vars:  !0 = $inner, !1 = $node, !2 = $value, !3 = $key, !4 = $attrVal, !5 = $attrKey, !6 = $subNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   84     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   86     2      > FE_RESET_R                                       $7      !0, ->28
          3    > > FE_FETCH_R                                       ~8      $7, !2, ->28
          4    >   ASSIGN                                                   !3, ~8
   87     5        IS_EQUAL                                                 !3, 'attributes'
          6      > JMPZ                                                     ~10, ->19
   88     7    >   COUNT                                            ~11     !2
          8      > JMPZ                                                     ~11, ->18
   89     9    > > FE_RESET_R                                       $12     !2, ->17
         10    > > FE_FETCH_R                                       ~13     $12, !4, ->17
         11    >   ASSIGN                                                   !5, ~13
   91    12        INIT_METHOD_CALL                                         !1, 'addAttribute'
         13        SEND_VAR_EX                                              !5
         14        SEND_VAR_EX                                              !4
         15        DO_FCALL                                      0          
   89    16      > JMP                                                      ->10
         17    >   FE_FREE                                                  $12
         18    > > JMP                                                      ->27
   95    19    >   INIT_METHOD_CALL                                         !1, 'addChild'
         20        SEND_VAR_EX                                              !3
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                                   !6, $16
   96    23        INIT_METHOD_CALL                                         'a2x'
         24        SEND_VAR_EX                                              !2
         25        SEND_VAR_EX                                              !6
         26        DO_FCALL                                      0          
   86    27    > > JMP                                                      ->3
         28    >   FE_FREE                                                  $7
   99    29        FETCH_OBJ_R                                      ~19     'res'
         30      > RETURN                                                   ~19
  100    31*     > RETURN                                                   null

End of function a2x

End of class Conv.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.97 ms | 1396 KiB | 17 Q