3v4l.org

run code in 500+ PHP versions simultaneously
<?php function count_words(string $string): int { return preg_match_all('/\b(?:[^\W\d_]|-)+\b/u', $string, $matches) ? count($matches[0]) : 0; } echo count_words(' - - - - - - - '), PHP_EOL; // 0 echo count_words('hello world'), PHP_EOL; // 2 echo count_words('hoho hé-hé haha'), PHP_EOL; // 3 echo count_words('hello 123'), PHP_EOL; // 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/18vq2
function name:  (null)
number of ops:  21
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                                   'count_words'
          1        SEND_VAL                                                     '+-+-+-+-+-+-+-+'
          2        DO_FCALL                                          0  $0      
          3        ECHO                                                         $0
          4        ECHO                                                         '%0A'
   11     5        INIT_FCALL                                                   'count_words'
          6        SEND_VAL                                                     'hello+world'
          7        DO_FCALL                                          0  $1      
          8        ECHO                                                         $1
          9        ECHO                                                         '%0A'
   12    10        INIT_FCALL                                                   'count_words'
         11        SEND_VAL                                                     'hoho+h%C3%A9-h%C3%A9+haha'
         12        DO_FCALL                                          0  $2      
         13        ECHO                                                         $2
         14        ECHO                                                         '%0A'
   13    15        INIT_FCALL                                                   'count_words'
         16        SEND_VAL                                                     'hello+123'
         17        DO_FCALL                                          0  $3      
         18        ECHO                                                         $3
         19        ECHO                                                         '%0A'
         20      > RETURN                                                       1

Function count_words:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/18vq2
function name:  count_words
number of ops:  16
compiled vars:  !0 = $string, !1 = $matches
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    5     1        INIT_FCALL                                                   'preg_match_all'
          2        SEND_VAL                                                     '%2F%5Cb%28%3F%3A%5B%5E%5CW%5Cd_%5D%7C-%29%2B%5Cb%2Fu'
          3        SEND_VAR                                                     !0
          4        SEND_REF                                                     !1
          5        DO_ICALL                                             $2      
          6      > JMPZ                                                         $2, ->11
    6     7    >   FETCH_DIM_R                                          ~3      !1, 0
          8        COUNT                                                ~4      ~3
          9        QM_ASSIGN                                            ~5      ~4
         10      > JMP                                                          ->12
    7    11    >   QM_ASSIGN                                            ~5      0
         12    >   VERIFY_RETURN_TYPE                                           ~5
         13      > RETURN                                                       ~5
    8    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null

End of function count_words

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.99 ms | 2095 KiB | 18 Q