3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Version { const STAGE_ALPHA = 1; const STAGE_BETA = 2; const STAGE_RC = 3; const STAGE_RELEASE = 4; public $major; public $minor; public $release; public $stageName; public $stageNo; private $stageMap = [ 'alpha' => self::STAGE_ALPHA, 'beta' => self::STAGE_BETA, 'rc' => self::STAGE_RC, ]; /** * @param string $version * @throws \Exception */ public function __construct($version) { static $tagNameExpr = '# ^ v? (?P<major>[0-9]+) \. (?P<minor>[0-9]+) (?:\.(?P<release>[0-9]+))? (?:- (?P<stage>alpha|beta|rc) (?:(?P<stageno>\d+))? )? $ #ix'; if (!preg_match($tagNameExpr, trim(strtolower($version)), $match)) { throw new \Exception('Invalid version spec string'); } $this->major = (int)$match['major']; $this->minor = (int)$match['minor']; $this->release = isset($match['release']) && $match['release'] !== '' ? (int)$match['release'] : null; $this->stageName = isset($match['stage']) && $match['stage'] !== '' ? $match['stage'] : ''; $this->stageNo = isset($match['stageno']) && $match['stageno'] !== '' ? (int)$match['stageno'] : null; } /** * @return string */ public function __toString() { return "$this->major.$this->minor." . ($this->release ?: 0) . ($this->stageNo ? '-' . $this->stageName . $this->stageNo : ''); } /** * @param string[] $stages * @return bool */ public function isValidNextStage(array $stages) { $latestStageType = $latestStagePoint = 0; foreach ($stages as $stage) { if ($stage === '') { // a release already exists return false; } if (preg_match('#^(alpha|beta|rc)(\d+)$#', strtolower($stage), $match)) { if ($this->stageMap[$match[1]] > $latestStageType) { $latestStageType = $this->stageMap[$match[1]]; $latestStagePoint = 0; } else if ($this->stageMap[$match[1]] === $latestStageType && $match[2] > $latestStagePoint) { $latestStagePoint = (int)$match[2]; } } } if (!$this->stageName) { // this is a release and one does not yet exist return true; } if (!isset($this->stageMap[$this->stageName])) { // invalid new stage return false; } if ($this->stageMap[$this->stageName] < $latestStageType) { // new stage lower than latest return false; } if ($this->stageMap[$this->stageName] > $latestStageType) { // new stage greater than latest, number must be 1 if (!isset($this->stageNo)) { $this->stageNo = 1; return true; } return $this->stageNo === 1; } if (!isset($this->stageNo)) { $this->stageNo = $latestStagePoint + 1; return true; } return $this->stageNo === $latestStagePoint + 1; } } var_dump(new Version('1.12-beta3'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/piDr2
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'version'
  120     1        INIT_FCALL                                               'var_dump'
          2        NEW                                              $0      'Version'
          3        SEND_VAL_EX                                              '1.12-beta3'
          4        DO_FCALL                                      0          
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Class Version:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 62
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
Branch analysis from position: 49
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
Branch analysis from position: 57
Branch analysis from position: 45
Branch analysis from position: 37
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
Branch analysis from position: 45
Branch analysis from position: 32
filename:       /in/piDr2
function name:  __construct
number of ops:  66
compiled vars:  !0 = $version, !1 = $tagNameExpr, !2 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        BIND_STATIC                                              !1
   42     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        INIT_FCALL                                               'trim'
          5        INIT_FCALL                                               'strtolower'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                         $4      
         10        SEND_VAR                                                 $4
         11        SEND_REF                                                 !2
         12        DO_ICALL                                         $5      
         13        BOOL_NOT                                         ~6      $5
         14      > JMPZ                                                     ~6, ->19
   43    15    >   NEW                                              $7      'Exception'
         16        SEND_VAL_EX                                              'Invalid+version+spec+string'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $7
   46    19    >   FETCH_DIM_R                                      ~10     !2, 'major'
         20        CAST                                          4  ~11     ~10
         21        ASSIGN_OBJ                                               'major'
         22        OP_DATA                                                  ~11
   47    23        FETCH_DIM_R                                      ~13     !2, 'minor'
         24        CAST                                          4  ~14     ~13
         25        ASSIGN_OBJ                                               'minor'
         26        OP_DATA                                                  ~14
   48    27        ISSET_ISEMPTY_DIM_OBJ                         0  ~16     !2, 'release'
         28      > JMPZ_EX                                          ~16     ~16, ->32
         29    >   FETCH_DIM_R                                      ~17     !2, 'release'
         30        IS_NOT_IDENTICAL                                 ~18     ~17, ''
         31        BOOL                                             ~16     ~18
         32    > > JMPZ                                                     ~16, ->37
         33    >   FETCH_DIM_R                                      ~19     !2, 'release'
         34        CAST                                          4  ~20     ~19
         35        QM_ASSIGN                                        ~21     ~20
         36      > JMP                                                      ->38
         37    >   QM_ASSIGN                                        ~21     null
         38    >   ASSIGN_OBJ                                               'release'
         39        OP_DATA                                                  ~21
   49    40        ISSET_ISEMPTY_DIM_OBJ                         0  ~23     !2, 'stage'
         41      > JMPZ_EX                                          ~23     ~23, ->45
         42    >   FETCH_DIM_R                                      ~24     !2, 'stage'
         43        IS_NOT_IDENTICAL                                 ~25     ~24, ''
         44        BOOL                                             ~23     ~25
         45    > > JMPZ                                                     ~23, ->49
         46    >   FETCH_DIM_R                                      ~26     !2, 'stage'
         47        QM_ASSIGN                                        ~27     ~26
         48      > JMP                                                      ->50
         49    >   QM_ASSIGN                                        ~27     ''
         50    >   ASSIGN_OBJ                                               'stageName'
         51        OP_DATA                                                  ~27
   50    52        ISSET_ISEMPTY_DIM_OBJ                         0  ~29     !2, 'stageno'
         53      > JMPZ_EX                                          ~29     ~29, ->57
         54    >   FETCH_DIM_R                                      ~30     !2, 'stageno'
         55        IS_NOT_IDENTICAL                                 ~31     ~30, ''
         56        BOOL                                             ~29     ~31
         57    > > JMPZ                                                     ~29, ->62
         58    >   FETCH_DIM_R                                      ~32     !2, 'stageno'
         59        CAST                                          4  ~33     ~32
         60        QM_ASSIGN                                        ~34     ~33
         61      > JMP                                                      ->63
         62    >   QM_ASSIGN                                        ~34     null
         63    >   ASSIGN_OBJ                                               'stageNo'
         64        OP_DATA                                                  ~34
   51    65      > RETURN                                                   null

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/piDr2
function name:  __toString
number of ops:  24
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   FETCH_OBJ_R                                      ~0      'major'
          1        ROPE_INIT                                     4  ~3      ~0
          2        ROPE_ADD                                      1  ~3      ~3, '.'
          3        FETCH_OBJ_R                                      ~1      'minor'
          4        ROPE_ADD                                      2  ~3      ~3, ~1
          5        ROPE_END                                      3  ~2      ~3, '.'
   59     6        FETCH_OBJ_R                                      ~5      'release'
          7        JMP_SET                                          ~6      ~5, ->9
          8        QM_ASSIGN                                        ~6      0
          9        CONCAT                                           ~7      ~2, ~6
   60    10        FETCH_OBJ_R                                      ~8      'stageNo'
         11      > JMPZ                                                     ~8, ->18
         12    >   FETCH_OBJ_R                                      ~9      'stageName'
         13        CONCAT                                           ~10     '-', ~9
         14        FETCH_OBJ_R                                      ~11     'stageNo'
         15        CONCAT                                           ~12     ~10, ~11
         16        QM_ASSIGN                                        ~13     ~12
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~13     ''
         19    >   CONCAT                                           ~14     ~7, ~13
         20        VERIFY_RETURN_TYPE                                       ~14
         21      > RETURN                                                   ~14
   61    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function __tostring

Function isvalidnextstage:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 42
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 42
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 41
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 41
Branch analysis from position: 37
Branch analysis from position: 41
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 47
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 53
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 59
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 73
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 70
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 80
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
filename:       /in/piDr2
function name:  isValidNextStage
number of ops:  85
compiled vars:  !0 = $stages, !1 = $latestStageType, !2 = $latestStagePoint, !3 = $stage, !4 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   RECV                                             !0      
   69     1        ASSIGN                                           ~5      !2, 0
          2        ASSIGN                                                   !1, ~5
   70     3      > FE_RESET_R                                       $7      !0, ->42
          4    > > FE_FETCH_R                                               $7, !3, ->42
   71     5    >   IS_IDENTICAL                                             !3, ''
          6      > JMPZ                                                     ~8, ->9
   73     7    >   FE_FREE                                                  $7
          8      > RETURN                                                   <false>
   76     9    >   INIT_FCALL                                               'preg_match'
         10        SEND_VAL                                                 '%23%5E%28alpha%7Cbeta%7Crc%29%28%5Cd%2B%29%24%23'
         11        INIT_FCALL                                               'strtolower'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $9      
         14        SEND_VAR                                                 $9
         15        SEND_REF                                                 !4
         16        DO_ICALL                                         $10     
         17      > JMPZ                                                     $10, ->41
   77    18    >   FETCH_DIM_R                                      ~12     !4, 1
         19        FETCH_OBJ_R                                      ~11     'stageMap'
         20        FETCH_DIM_R                                      ~13     ~11, ~12
         21        IS_SMALLER                                               !1, ~13
         22      > JMPZ                                                     ~14, ->29
   78    23    >   FETCH_DIM_R                                      ~16     !4, 1
         24        FETCH_OBJ_R                                      ~15     'stageMap'
         25        FETCH_DIM_R                                      ~17     ~15, ~16
         26        ASSIGN                                                   !1, ~17
   79    27        ASSIGN                                                   !2, 0
         28      > JMP                                                      ->41
   80    29    >   FETCH_DIM_R                                      ~21     !4, 1
         30        FETCH_OBJ_R                                      ~20     'stageMap'
         31        FETCH_DIM_R                                      ~22     ~20, ~21
         32        IS_IDENTICAL                                     ~23     !1, ~22
         33      > JMPZ_EX                                          ~23     ~23, ->37
         34    >   FETCH_DIM_R                                      ~24     !4, 2
         35        IS_SMALLER                                       ~25     !2, ~24
         36        BOOL                                             ~23     ~25
         37    > > JMPZ                                                     ~23, ->41
   81    38    >   FETCH_DIM_R                                      ~26     !4, 2
         39        CAST                                          4  ~27     ~26
         40        ASSIGN                                                   !2, ~27
   70    41    > > JMP                                                      ->4
         42    >   FE_FREE                                                  $7
   86    43        FETCH_OBJ_R                                      ~29     'stageName'
         44        BOOL_NOT                                         ~30     ~29
         45      > JMPZ                                                     ~30, ->47
   88    46    > > RETURN                                                   <true>
   91    47    >   FETCH_OBJ_R                                      ~32     'stageName'
         48        FETCH_OBJ_IS                                     ~31     'stageMap'
         49        ISSET_ISEMPTY_DIM_OBJ                         0  ~33     ~31, ~32
         50        BOOL_NOT                                         ~34     ~33
         51      > JMPZ                                                     ~34, ->53
   93    52    > > RETURN                                                   <false>
   96    53    >   FETCH_OBJ_R                                      ~36     'stageName'
         54        FETCH_OBJ_R                                      ~35     'stageMap'
         55        FETCH_DIM_R                                      ~37     ~35, ~36
         56        IS_SMALLER                                               ~37, !1
         57      > JMPZ                                                     ~38, ->59
   98    58    > > RETURN                                                   <false>
  101    59    >   FETCH_OBJ_R                                      ~40     'stageName'
         60        FETCH_OBJ_R                                      ~39     'stageMap'
         61        FETCH_DIM_R                                      ~41     ~39, ~40
         62        IS_SMALLER                                               !1, ~41
         63      > JMPZ                                                     ~42, ->73
  103    64    >   ISSET_ISEMPTY_PROP_OBJ                           ~43     'stageNo'
         65        BOOL_NOT                                         ~44     ~43
         66      > JMPZ                                                     ~44, ->70
  104    67    >   ASSIGN_OBJ                                               'stageNo'
         68        OP_DATA                                                  1
  105    69      > RETURN                                                   <true>
  108    70    >   FETCH_OBJ_R                                      ~46     'stageNo'
         71        IS_IDENTICAL                                     ~47     ~46, 1
         72      > RETURN                                                   ~47
  111    73    >   ISSET_ISEMPTY_PROP_OBJ                           ~48     'stageNo'
         74        BOOL_NOT                                         ~49     ~48
         75      > JMPZ                                                     ~49, ->80
  112    76    >   ADD                                              ~51     !2, 1
         77        ASSIGN_OBJ                                               'stageNo'
         78        OP_DATA                                                  ~51
  113    79      > RETURN                                                   <true>
  116    80    >   FETCH_OBJ_R                                      ~52     'stageNo'
         81        ADD                                              ~53     !2, 1
         82        IS_IDENTICAL                                     ~54     ~52, ~53
         83      > RETURN                                                   ~54
  117    84*     > RETURN                                                   null

End of function isvalidnextstage

End of class Version.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.03 ms | 1416 KiB | 21 Q