3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PasswordValidation { public static function digitCount($string) { return self::occurrencesCount($string, '/[0-9]/'); } public static function lcCount($string) { return self::occurrencesCount($string, '/[a-z]/'); } public static function ucCount($string) { return self::occurrencesCount($string, '/[A-Z]/'); } public static function nonAlphaNumCount($string) { return self::occurrencesCount($string, '/[^0-9a-zA-Z]/'); } public static function repeatedCharCount($string) { $lcString = strtolower($string); $prevChar = $lcString[0]; $currentLen = 0; $maxLen = 0; for ($i = 1; $i < strlen($lcString); $i++) { if ($lcString[$i] === $prevChar) { $currentLen += 1; } else { $currentLen = 1; } $maxLen = max($maxLen, $currentLen); $prevChar = $lcString[$i]; } return $maxLen; } public static function consecutiveCharCount($string) { $lcString = strtolower($string); $prevChar = $lcString[0]; $currentLen = 0; $maxLen = 0; $ascending = null; for ($i = 1; $i < strlen($lcString); $i++) { $diff = ord($lcString[$i]) - ord($prevChar); if ($diff == 1) { if ($ascending !== true) { $ascending = true; $currentLen = 1; } $currentLen += 1; } elseif ($diff == -1) { if ($ascending !== false) { $ascending = false; $currentLen = 1; } $currentLen += 1; } else { $currentLen = 1; } $maxLen = max($maxLen, $currentLen); $prevChar = $lcString[$i]; } return $maxLen; } private static function occurrencesCount($string, $regex) { preg_match_all($regex, $string, $matches); return count($matches[0]); } } echo PasswordValidation::consecutiveCharCount("abcdegionoas"); echo "\r\n"; echo PasswordValidation::consecutiveCharCount("EDCb00808asabc"); echo "\r\n"; echo PasswordValidation::consecutiveCharCount("asg7898"); echo "\r\n"; echo PasswordValidation::consecutiveCharCount("asgab876567asfon"); echo "\r\n"; echo PasswordValidation::repeatedCharCount("abcdegionoas"); echo "\r\n"; echo PasswordValidation::repeatedCharCount("EDCb00808asabc"); echo "\r\n"; echo PasswordValidation::repeatedCharCount("asg7898"); echo "\r\n"; echo PasswordValidation::repeatedCharCount("asgaaaCCc656bBBb7asfon"); echo "\r\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WNBrn
function name:  (null)
number of ops:  41
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'consecutiveCharCount'
          1        SEND_VAL                                                 'abcdegionoas'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   82     4        ECHO                                                     '%0D%0A'
   83     5        INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'consecutiveCharCount'
          6        SEND_VAL                                                 'EDCb00808asabc'
          7        DO_FCALL                                      0  $1      
          8        ECHO                                                     $1
   84     9        ECHO                                                     '%0D%0A'
   85    10        INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'consecutiveCharCount'
         11        SEND_VAL                                                 'asg7898'
         12        DO_FCALL                                      0  $2      
         13        ECHO                                                     $2
   86    14        ECHO                                                     '%0D%0A'
   87    15        INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'consecutiveCharCount'
         16        SEND_VAL                                                 'asgab876567asfon'
         17        DO_FCALL                                      0  $3      
         18        ECHO                                                     $3
   88    19        ECHO                                                     '%0D%0A'
   89    20        INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'repeatedCharCount'
         21        SEND_VAL                                                 'abcdegionoas'
         22        DO_FCALL                                      0  $4      
         23        ECHO                                                     $4
   90    24        ECHO                                                     '%0D%0A'
   91    25        INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'repeatedCharCount'
         26        SEND_VAL                                                 'EDCb00808asabc'
         27        DO_FCALL                                      0  $5      
         28        ECHO                                                     $5
   92    29        ECHO                                                     '%0D%0A'
   93    30        INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'repeatedCharCount'
         31        SEND_VAL                                                 'asg7898'
         32        DO_FCALL                                      0  $6      
         33        ECHO                                                     $6
   94    34        ECHO                                                     '%0D%0A'
   95    35        INIT_STATIC_METHOD_CALL                                  'PasswordValidation', 'repeatedCharCount'
         36        SEND_VAL                                                 'asgaaaCCc656bBBb7asfon'
         37        DO_FCALL                                      0  $7      
         38        ECHO                                                     $7
   96    39        ECHO                                                     '%0D%0A'
         40      > RETURN                                                   1

Class PasswordValidation:
Function digitcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WNBrn
function name:  digitCount
number of ops:  7
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        INIT_STATIC_METHOD_CALL                                  'occurrencesCount'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              '%2F%5B0-9%5D%2F'
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
    7     6*     > RETURN                                                   null

End of function digitcount

Function lccount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WNBrn
function name:  lcCount
number of ops:  7
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        INIT_STATIC_METHOD_CALL                                  'occurrencesCount'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              '%2F%5Ba-z%5D%2F'
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   12     6*     > RETURN                                                   null

End of function lccount

Function uccount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WNBrn
function name:  ucCount
number of ops:  7
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        INIT_STATIC_METHOD_CALL                                  'occurrencesCount'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              '%2F%5BA-Z%5D%2F'
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   17     6*     > RETURN                                                   null

End of function uccount

Function nonalphanumcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WNBrn
function name:  nonAlphaNumCount
number of ops:  7
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        INIT_STATIC_METHOD_CALL                                  'occurrencesCount'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              '%2F%5B%5E0-9a-zA-Z%5D%2F'
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   22     6*     > RETURN                                                   null

End of function nonalphanumcount

Function repeatedcharcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 11
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 11
Branch analysis from position: 28
Branch analysis from position: 11
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 11
Branch analysis from position: 28
Branch analysis from position: 11
filename:       /in/WNBrn
function name:  repeatedCharCount
number of ops:  30
compiled vars:  !0 = $string, !1 = $lcString, !2 = $prevChar, !3 = $currentLen, !4 = $maxLen, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'strtolower'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4        ASSIGN                                                   !1, $6
   27     5        FETCH_DIM_R                                      ~8      !1, 0
          6        ASSIGN                                                   !2, ~8
   28     7        ASSIGN                                                   !3, 0
   29     8        ASSIGN                                                   !4, 0
   30     9        ASSIGN                                                   !5, 1
         10      > JMP                                                      ->25
   31    11    >   FETCH_DIM_R                                      ~13     !1, !5
         12        IS_IDENTICAL                                             !2, ~13
         13      > JMPZ                                                     ~14, ->16
   32    14    >   ASSIGN_OP                                     1          !3, 1
         15      > JMP                                                      ->17
   34    16    >   ASSIGN                                                   !3, 1
   36    17    >   INIT_FCALL                                               'max'
         18        SEND_VAR                                                 !4
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $17     
         21        ASSIGN                                                   !4, $17
   37    22        FETCH_DIM_R                                      ~19     !1, !5
         23        ASSIGN                                                   !2, ~19
   30    24        PRE_INC                                                  !5
         25    >   STRLEN                                           ~22     !1
         26        IS_SMALLER                                               !5, ~22
         27      > JMPNZ                                                    ~23, ->11
   40    28    > > RETURN                                                   !4
   41    29*     > RETURN                                                   null

End of function repeatedcharcount

Function consecutivecharcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 12
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 12
Branch analysis from position: 49
Branch analysis from position: 12
Branch analysis from position: 27
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 35
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 35
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 12
Branch analysis from position: 49
Branch analysis from position: 12
filename:       /in/WNBrn
function name:  consecutiveCharCount
number of ops:  51
compiled vars:  !0 = $string, !1 = $lcString, !2 = $prevChar, !3 = $currentLen, !4 = $maxLen, !5 = $ascending, !6 = $i, !7 = $diff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   45     1        INIT_FCALL                                               'strtolower'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
   46     5        FETCH_DIM_R                                      ~10     !1, 0
          6        ASSIGN                                                   !2, ~10
   47     7        ASSIGN                                                   !3, 0
   48     8        ASSIGN                                                   !4, 0
   49     9        ASSIGN                                                   !5, null
   50    10        ASSIGN                                                   !6, 1
         11      > JMP                                                      ->46
   51    12    >   INIT_FCALL                                               'ord'
         13        FETCH_DIM_R                                      ~16     !1, !6
         14        SEND_VAL                                                 ~16
         15        DO_ICALL                                         $17     
         16        INIT_FCALL                                               'ord'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $18     
         19        SUB                                              ~19     $17, $18
         20        ASSIGN                                                   !7, ~19
   52    21        IS_EQUAL                                                 !7, 1
         22      > JMPZ                                                     ~21, ->29
   53    23    >   TYPE_CHECK                                  1014          !5
         24      > JMPZ                                                     ~22, ->27
   54    25    >   ASSIGN                                                   !5, <true>
   55    26        ASSIGN                                                   !3, 1
   57    27    >   ASSIGN_OP                                     1          !3, 1
         28      > JMP                                                      ->38
   58    29    >   IS_EQUAL                                                 !7, -1
         30      > JMPZ                                                     ~26, ->37
   59    31    >   TYPE_CHECK                                  1018          !5
         32      > JMPZ                                                     ~27, ->35
   60    33    >   ASSIGN                                                   !5, <false>
   61    34        ASSIGN                                                   !3, 1
   63    35    >   ASSIGN_OP                                     1          !3, 1
         36      > JMP                                                      ->38
   65    37    >   ASSIGN                                                   !3, 1
   67    38    >   INIT_FCALL                                               'max'
         39        SEND_VAR                                                 !4
         40        SEND_VAR                                                 !3
         41        DO_ICALL                                         $32     
         42        ASSIGN                                                   !4, $32
   68    43        FETCH_DIM_R                                      ~34     !1, !6
         44        ASSIGN                                                   !2, ~34
   50    45        PRE_INC                                                  !6
         46    >   STRLEN                                           ~37     !1
         47        IS_SMALLER                                               !6, ~37
         48      > JMPNZ                                                    ~38, ->12
   71    49    > > RETURN                                                   !4
   72    50*     > RETURN                                                   null

End of function consecutivecharcount

Function occurrencescount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WNBrn
function name:  occurrencesCount
number of ops:  11
compiled vars:  !0 = $string, !1 = $regex, !2 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   76     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
   77     7        FETCH_DIM_R                                      ~4      !2, 0
          8        COUNT                                            ~5      ~4
          9      > RETURN                                                   ~5
   78    10*     > RETURN                                                   null

End of function occurrencescount

End of class PasswordValidation.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.92 ms | 1412 KiB | 21 Q