3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { protected function generate(int $length = 4): string { $randomString = ''; $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; for ($i = 0; $i < $length; $i++) { $index = random_int(0, strlen($characters) - 1); $randomString .= $characters[$index]; } $uppercase = preg_match('@^[A-Z]+$@', $randomString); $number = preg_match('@^\d+$@', $randomString); if ($uppercase || $number) { $randomString = $this->generate(); } return $randomString; } public function getRandomString() { return $this->generate(); } } $test = new Test(); for ($i = 0; $i < 10; $i++) { echo $test->getRandomString() . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
Branch analysis from position: 5
filename:       /in/80B7Q
function name:  (null)
number of ops:  13
compiled vars:  !0 = $test, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   NEW                                              $2      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   32     3        ASSIGN                                                   !1, 0
          4      > JMP                                                      ->10
   33     5    >   INIT_METHOD_CALL                                         !0, 'getRandomString'
          6        DO_FCALL                                      0  $6      
          7        CONCAT                                           ~7      $6, '%0A'
          8        ECHO                                                     ~7
   32     9        PRE_INC                                                  !1
         10    >   IS_SMALLER                                               !1, 10
         11      > JMPNZ                                                    ~9, ->5
   34    12    > > RETURN                                                   1

Class Test:
Function generate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 29
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 33
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 29
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
Branch analysis from position: 5
filename:       /in/80B7Q
function name:  generate
number of ops:  37
compiled vars:  !0 = $length, !1 = $randomString, !2 = $characters, !3 = $i, !4 = $index, !5 = $uppercase, !6 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV_INIT                                        !0      4
    6     1        ASSIGN                                                   !1, ''
    8     2        ASSIGN                                                   !2, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    9     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->15
   10     5    >   INIT_FCALL                                               'random_int'
          6        SEND_VAL                                                 0
          7        STRLEN                                           ~10     !2
          8        SUB                                              ~11     ~10, 1
          9        SEND_VAL                                                 ~11
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !4, $12
   11    12        FETCH_DIM_R                                      ~14     !2, !4
         13        ASSIGN_OP                                     8          !1, ~14
    9    14        PRE_INC                                                  !3
         15    >   IS_SMALLER                                               !3, !0
         16      > JMPNZ                                                    ~17, ->5
   14    17    >   INIT_FCALL                                               'preg_match'
         18        SEND_VAL                                                 '%40%5E%5BA-Z%5D%2B%24%40'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $18     
         21        ASSIGN                                                   !5, $18
   15    22        INIT_FCALL                                               'preg_match'
         23        SEND_VAL                                                 '%40%5E%5Cd%2B%24%40'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $20     
         26        ASSIGN                                                   !6, $20
   18    27      > JMPNZ_EX                                         ~22     !5, ->29
         28    >   BOOL                                             ~22     !6
         29    > > JMPZ                                                     ~22, ->33
   19    30    >   INIT_METHOD_CALL                                         'generate'
         31        DO_FCALL                                      0  $23     
         32        ASSIGN                                                   !1, $23
   22    33    >   VERIFY_RETURN_TYPE                                       !1
         34      > RETURN                                                   !1
   23    35*       VERIFY_RETURN_TYPE                                       
         36*     > RETURN                                                   null

End of function generate

Function getrandomstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/80B7Q
function name:  getRandomString
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_METHOD_CALL                                         'generate'
          1        DO_FCALL                                      0  $0      
          2      > RETURN                                                   $0
   27     3*     > RETURN                                                   null

End of function getrandomstring

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.17 ms | 1016 KiB | 15 Q