3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Arrayable { public function toArray(); } class Item implements Arrayable { protected $attributes = array(); protected $someParameter = true; public function __construct($attributes) { $this->attributes = $attributes; } public function toArray() { return $this->attributes; } public function __toArray() { return $this->toArray(); } } class ItemCollection implements Arrayable { protected $items = array(); public function addItem(Item $item) { $this->items[] = $item; } public function toArray() { $result = array(); foreach ($this->items as $item) { $result[] = $item->toArray(); } return $result; } public function __toArray() { return $this->toArray(); } } $array = array('foo' => 'bar', 'baz' => 'qux'); $item = new Item($array); print_r((array) $item); print_r($item->toArray()); $collection = new ItemCollection(); $collection->addItem($item); $collection->addItem($item); print_r((array) $collection); print_r($collection->toArray());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQDaJ
function name:  (null)
number of ops:  35
compiled vars:  !0 = $array, !1 = $item, !2 = $collection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_CLASS                                            'item'
   27     1        DECLARE_CLASS                                            'itemcollection'
   50     2        ASSIGN                                                   !0, <array>
   52     3        NEW                                              $4      'Item'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $4
   54     7        INIT_FCALL                                               'print_r'
          8        CAST                                          7  ~7      !1
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                                 
   55    11        INIT_FCALL                                               'print_r'
         12        INIT_METHOD_CALL                                         !1, 'toArray'
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR                                                 $9
         15        DO_ICALL                                                 
   57    16        NEW                                              $11     'ItemCollection'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !2, $11
   58    19        INIT_METHOD_CALL                                         !2, 'addItem'
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0          
   59    22        INIT_METHOD_CALL                                         !2, 'addItem'
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0          
   61    25        INIT_FCALL                                               'print_r'
         26        CAST                                          7  ~16     !2
         27        SEND_VAL                                                 ~16
         28        DO_ICALL                                                 
   62    29        INIT_FCALL                                               'print_r'
         30        INIT_METHOD_CALL                                         !2, 'toArray'
         31        DO_FCALL                                      0  $18     
         32        SEND_VAR                                                 $18
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Class Arrayable:
Function toarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQDaJ
function name:  toArray
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   null

End of function toarray

End of class Arrayable.

Class Item:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQDaJ
function name:  __construct
number of ops:  4
compiled vars:  !0 = $attributes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN_OBJ                                               'attributes'
          2        OP_DATA                                                  !0
   14     3      > RETURN                                                   null

End of function __construct

Function toarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQDaJ
function name:  toArray
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   FETCH_OBJ_R                                      ~0      'attributes'
          1      > RETURN                                                   ~0
   19     2*     > RETURN                                                   null

End of function toarray

Function __toarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQDaJ
function name:  __toArray
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_METHOD_CALL                                         'toArray'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   24     3*     > RETURN                                                   null

End of function __toarray

End of class Item.

Class ItemCollection:
Function additem:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQDaJ
function name:  addItem
number of ops:  5
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   32     1        FETCH_OBJ_W                                      $1      'items'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   33     4      > RETURN                                                   null

End of function additem

Function toarray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/IQDaJ
function name:  toArray
number of ops:  12
compiled vars:  !0 = $result, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   ASSIGN                                                   !0, <array>
   38     1        FETCH_OBJ_R                                      ~3      'items'
          2      > FE_RESET_R                                       $4      ~3, ->9
          3    > > FE_FETCH_R                                               $4, !1, ->9
   39     4    >   INIT_METHOD_CALL                                         !1, 'toArray'
          5        DO_FCALL                                      0  $6      
          6        ASSIGN_DIM                                               !0
          7        OP_DATA                                                  $6
   38     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $4
   41    10      > RETURN                                                   !0
   42    11*     > RETURN                                                   null

End of function toarray

Function __toarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IQDaJ
function name:  __toArray
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   INIT_METHOD_CALL                                         'toArray'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   47     3*     > RETURN                                                   null

End of function __toarray

End of class ItemCollection.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.43 ms | 1404 KiB | 15 Q