3v4l.org

run code in 500+ PHP versions simultaneously
<?php function countUniqueCharacters(string $str): int { static $cache = []; if (key_exists($str, $cache)) { return $cache[$str]; } echo PHP_EOL . "*** doing the work ***"; return $cache[$str] = count( array_filter( count_chars($str, 1), fn($count) => $count === 1 ) ); } $tests = ['one', 'two', 'three', 'one', 'two']; foreach ($tests as $test) { echo PHP_EOL . "$test : " . countUniqueCharacters($test); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/9JBnc
function name:  (null)
number of ops:  14
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                       !0, <array>
   22     1      > FE_RESET_R                                           $3      !0, ->12
          2    > > FE_FETCH_R                                                   $3, !1, ->12
   23     3    >   NOP                                                          
          4        FAST_CONCAT                                          ~4      !1, '+%3A+'
          5        CONCAT                                               ~5      '%0A', ~4
          6        INIT_FCALL                                                   'countuniquecharacters'
          7        SEND_VAR                                                     !1
          8        DO_FCALL                                          0  $6      
          9        CONCAT                                               ~7      ~5, $6
         10        ECHO                                                         ~7
   22    11      > JMP                                                          ->2
         12    >   FE_FREE                                                      $3
   24    13      > RETURN                                                       1

Function countuniquecharacters:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9JBnc
function name:  countUniqueCharacters
number of ops:  27
compiled vars:  !0 = $str, !1 = $cache
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    5     1        BIND_STATIC                                                  !1
    6     2        INIT_FCALL                                                   'key_exists'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_ICALL                                             $2      
          6      > JMPZ                                                         $2, ->10
    7     7    >   FETCH_DIM_R                                          ~3      !1, !0
          8        VERIFY_RETURN_TYPE                                           ~3
          9      > RETURN                                                       ~3
   10    10    >   ECHO                                                         '%0A%2A%2A%2A+doing+the+work+%2A%2A%2A'
   13    11        INIT_FCALL                                                   'array_filter'
   14    12        INIT_FCALL                                                   'count_chars'
         13        SEND_VAR                                                     !0
         14        SEND_VAL                                                     1
         15        DO_ICALL                                             $5      
         16        SEND_VAR                                                     $5
   15    17        DECLARE_LAMBDA_FUNCTION                              ~6      [0]
   16    18        SEND_VAL                                                     ~6
   13    19        DO_ICALL                                             $7      
   16    20        COUNT                                                ~8      $7
   12    21        ASSIGN_DIM                                           ~4      !1, !0
   16    22        OP_DATA                                                      ~8
         23        VERIFY_RETURN_TYPE                                           ~4
         24      > RETURN                                                       ~4
   18    25*       VERIFY_RETURN_TYPE                                           
         26*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9JBnc
function name:  {closure:countUniqueCharacters():15}
number of ops:  4
compiled vars:  !0 = $count
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        IS_IDENTICAL                                         ~1      !0, 1
          2      > RETURN                                                       ~1
   16     3*     > RETURN                                                       null

End of Dynamic Function 0

End of function countuniquecharacters

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
151.58 ms | 1921 KiB | 16 Q