3v4l.org

run code in 300+ PHP versions simultaneously
<?php $names = ['Alice', 'Bob', 'Charlie', 'Alice', 'Dave', 'Alice']; class Name { public $name; public $id; public function __construct($name, $id = 0) { $this->name = $name; $this->id = $id; } } function contains(array $list, $item) { foreach ($list as $test) { if ($item->name == $test->name) { return true; } } return false; } // Transform strings -> objects $mappedNames = array_map(function($name) { return new Name($name); }, $names); // Deduplicate list $reducedNames = array_reduce($mappedNames, function($carry, $item) { if (contains($carry, $item)) { return $carry; } return array_merge($carry, array($item)); }, []); $idNames = array_map(function($item, $id) { return new Name($item->name, $id); }, $reducedNames, range(1, count($reducedNames))); var_dump($idNames);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cdkbF
function name:  (null)
number of ops:  30
compiled vars:  !0 = $names, !1 = $mappedNames, !2 = $reducedNames, !3 = $idNames
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FcdkbF%3A24%240'
          3        SEND_VAL                                                 ~5
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !1, $6
   27     7        INIT_FCALL                                               'array_reduce'
          8        SEND_VAR                                                 !1
          9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FcdkbF%3A27%241'
   32    10        SEND_VAL                                                 ~8
         11        SEND_VAL                                                 <array>
         12        DO_ICALL                                         $9      
   27    13        ASSIGN                                                   !2, $9
   34    14        INIT_FCALL                                               'array_map'
         15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FcdkbF%3A34%242'
   36    16        SEND_VAL                                                 ~11
         17        SEND_VAR                                                 !2
         18        INIT_FCALL                                               'range'
         19        SEND_VAL                                                 1
         20        COUNT                                            ~12     !2
         21        SEND_VAL                                                 ~12
         22        DO_ICALL                                         $13     
         23        SEND_VAR                                                 $13
         24        DO_ICALL                                         $14     
   34    25        ASSIGN                                                   !3, $14
   38    26        INIT_FCALL                                               'var_dump'
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                                 
         29      > RETURN                                                   1

Function contains:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/cdkbF
function name:  contains
number of ops:  14
compiled vars:  !0 = $list, !1 = $item, !2 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2      > FE_RESET_R                                       $3      !0, ->11
          3    > > FE_FETCH_R                                               $3, !2, ->11
   16     4    >   FETCH_OBJ_R                                      ~4      !1, 'name'
          5        FETCH_OBJ_R                                      ~5      !2, 'name'
          6        IS_EQUAL                                                 ~4, ~5
          7      > JMPZ                                                     ~6, ->10
   17     8    >   FE_FREE                                                  $3
          9      > RETURN                                                   <true>
   15    10    > > JMP                                                      ->3
         11    >   FE_FREE                                                  $3
   20    12      > RETURN                                                   <false>
   21    13*     > RETURN                                                   null

End of function contains

Function %00%7Bclosure%7D%2Fin%2FcdkbF%3A24%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cdkbF
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        NEW                                              $1      'Name'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FcdkbF%3A24%240

Function %00%7Bclosure%7D%2Fin%2FcdkbF%3A27%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cdkbF
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $carry, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        INIT_FCALL                                               'contains'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $2      
          6      > JMPZ                                                     $2, ->8
   29     7    > > RETURN                                                   !0
   31     8    >   INIT_FCALL                                               'array_merge'
          9        SEND_VAR                                                 !0
         10        INIT_ARRAY                                       ~3      !1
         11        SEND_VAL                                                 ~3
         12        DO_ICALL                                         $4      
         13      > RETURN                                                   $4
   32    14*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FcdkbF%3A27%241

Function %00%7Bclosure%7D%2Fin%2FcdkbF%3A34%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cdkbF
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $item, !1 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   35     2        NEW                                              $2      'Name'
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $3      !0, 'name'
          5        SEND_FUNC_ARG                                            $3
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
          8      > RETURN                                                   $2
   36     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FcdkbF%3A34%242

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

End of function __construct

End of class Name.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.16 ms | 1407 KiB | 24 Q