3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Person { public $id; public $name; public $phones = []; public function __construct($id, $name) { $this->id = $id; $this->name = $name; } public function addPhone($phone) { $this->phones[] = $phone; } } /** * @return Person[] */ function statementToPersonList(iterable $stmt): array { $personList = []; foreach ($stmt as $row) { $id = $row['id']; $name = $row['name']; $number = $row['number']; if (!isset($personList[$name])) { $personList[$name] = new Person($id, $name); } $personList[$name]->addPhone($number); } return $personList; } $personList = statementToPersonList([ ['id' => 1, 'name' => 'Alice', 'number' => 'n1'], ['id' => 2, 'name' => 'Alice', 'number' => 'n2'], ['id' => 3, 'name' => 'Bob', 'number' => 'n3'], ['id' => 4, 'name' => 'Carol', 'number' => 'n4'], ['id' => 5, 'name' => 'Alice', 'number' => 'n5'], ]); print_r($personList);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YBFdQ
function name:  (null)
number of ops:  8
compiled vars:  !0 = $personList
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   INIT_FCALL                                               'statementtopersonlist'
   44     1        SEND_VAL                                                 <array>
   43     2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   51     4        INIT_FCALL                                               'print_r'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function statementtopersonlist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 24
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/YBFdQ
function name:  statementToPersonList
number of ops:  29
compiled vars:  !0 = $stmt, !1 = $personList, !2 = $row, !3 = $id, !4 = $name, !5 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        ASSIGN                                                   !1, <array>
   28     2      > FE_RESET_R                                       $7      !0, ->24
          3    > > FE_FETCH_R                                               $7, !2, ->24
   29     4    >   FETCH_DIM_R                                      ~8      !2, 'id'
          5        ASSIGN                                                   !3, ~8
   30     6        FETCH_DIM_R                                      ~10     !2, 'name'
          7        ASSIGN                                                   !4, ~10
   31     8        FETCH_DIM_R                                      ~12     !2, 'number'
          9        ASSIGN                                                   !5, ~12
   33    10        ISSET_ISEMPTY_DIM_OBJ                         0  ~14     !1, !4
         11        BOOL_NOT                                         ~15     ~14
         12      > JMPZ                                                     ~15, ->19
   34    13    >   NEW                                              $17     'Person'
         14        SEND_VAR_EX                                              !3
         15        SEND_VAR_EX                                              !4
         16        DO_FCALL                                      0          
         17        ASSIGN_DIM                                               !1, !4
         18        OP_DATA                                                  $17
   37    19    >   FETCH_DIM_R                                      ~19     !1, !4
         20        INIT_METHOD_CALL                                         ~19, 'addPhone'
         21        SEND_VAR_EX                                              !5
         22        DO_FCALL                                      0          
   28    23      > JMP                                                      ->3
         24    >   FE_FREE                                                  $7
   40    25        VERIFY_RETURN_TYPE                                       !1
         26      > RETURN                                                   !1
   41    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function statementtopersonlist

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

End of function __construct

Function addphone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YBFdQ
function name:  addPhone
number of ops:  5
compiled vars:  !0 = $phone
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_W                                      $1      'phones'
          2        ASSIGN_DIM                                               $1
          3        OP_DATA                                                  !0
   18     4      > RETURN                                                   null

End of function addphone

End of class Person.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.18 ms | 1005 KiB | 15 Q