3v4l.org

run code in 500+ PHP versions simultaneously
<?php function countUniqueCharacters(string $str): int { static $cache = []; 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/9PAT2
function name:  (null)
number of ops:  14
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                       !0, <array>
   16     1      > FE_RESET_R                                           $3      !0, ->12
          2    > > FE_FETCH_R                                                   $3, !1, ->12
   17     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
   16    11      > JMP                                                          ->2
         12    >   FE_FREE                                                      $3
   18    13      > RETURN                                                       1

Function countuniquecharacters:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9PAT2
function name:  countUniqueCharacters
number of ops:  21
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        FETCH_DIM_IS                                         ~2      !1, !0
          3        COALESCE                                             ~3      ~2
    7     4        INIT_FCALL                                                   'array_filter'
    8     5        INIT_FCALL                                                   'count_chars'
          6        SEND_VAR                                                     !0
          7        SEND_VAL                                                     1
          8        DO_ICALL                                             $4      
          9        SEND_VAR                                                     $4
    9    10        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
   10    11        SEND_VAL                                                     ~5
    7    12        DO_ICALL                                             $6      
   10    13        COUNT                                                ~7      $6
    6    14        ASSIGN_DIM                                           ~8      !1, !0
         15        OP_DATA                                                      ~7
         16        QM_ASSIGN                                            ~3      ~8
         17        VERIFY_RETURN_TYPE                                           ~3
         18      > RETURN                                                       ~3
   12    19*       VERIFY_RETURN_TYPE                                           
         20*     > 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/9PAT2
function name:  {closure:countUniqueCharacters():9}
number of ops:  4
compiled vars:  !0 = $count
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
          1        IS_IDENTICAL                                         ~1      !0, 1
          2      > RETURN                                                       ~1
   10     3*     > RETURN                                                       null

End of Dynamic Function 0

End of function countuniquecharacters

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
188.95 ms | 1891 KiB | 16 Q