3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); class DateValidator { const DATE_FORMAT = 'd/m/Y'; // DD/MM/YYYY const DATE_EXP = '/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/'; public static function validateHistoricalDate(string $dateString): HistoricalDate { $historicalDate = new HistoricalDate($dateString); $date = DateTime::createFromFormat(self::DATE_FORMAT, $dateString); if (!$date || !preg_match(self::DATE_EXP, $dateString, $dateParts)) { $historicalDate->setMessage('Date is not in the required format DD/MM/YYYY [PHP - d/m/Y]'); return $historicalDate; } if (!checkdate((int) $dateParts[2], (int) $dateParts[1], (int) $dateParts[3])) { $historicalDate->setMessage('Date is not valid'); return $historicalDate; } if ($date > new DateTime()) { $historicalDate->setMessage('Date is not historical'); return $historicalDate; } $historicalDate->setValidity(true); return $historicalDate; } } class HistoricalDate { private $date; private $valid = false; private $message = ''; public function __construct(string $date) { $this->setDate($date); } public function setValidity(bool $value) { $this->valid = $value; } public function setMessage(string $message) { $this->message = $message; } public function isValid(): bool { return $this->valid; } public function getMessage(): string { return $this->message; } public function getDate(): string { return $this->date; } private function setDate(string $date) { $this->date = $date; } } $dateString = "99/02/2017"; $result = DateValidator::validateHistoricalDate($dateString); if (!$result->isValid()) { $message = $result->getMessage(); } echo $result->isValid() ? 'Valid date' : $message;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/jh17i
function name:  (null)
number of ops:  20
compiled vars:  !0 = $dateString, !1 = $result, !2 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   ASSIGN                                                   !0, '99%2F02%2F2017'
   76     1        INIT_STATIC_METHOD_CALL                                  'DateValidator', 'validateHistoricalDate'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   77     5        INIT_METHOD_CALL                                         !1, 'isValid'
          6        DO_FCALL                                      0  $6      
          7        BOOL_NOT                                         ~7      $6
          8      > JMPZ                                                     ~7, ->12
   78     9    >   INIT_METHOD_CALL                                         !1, 'getMessage'
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !2, $8
   81    12    >   INIT_METHOD_CALL                                         !1, 'isValid'
         13        DO_FCALL                                      0  $10     
         14      > JMPZ                                                     $10, ->17
         15    >   QM_ASSIGN                                        ~11     'Valid+date'
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~11     !2
         18    >   ECHO                                                     ~11
         19      > RETURN                                                   1

Class DateValidator:
Function validatehistoricaldate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 19
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 43
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 52
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/jh17i
function name:  validateHistoricalDate
number of ops:  59
compiled vars:  !0 = $dateString, !1 = $historicalDate, !2 = $date, !3 = $dateParts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        NEW                                              $4      'HistoricalDate'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $4
   11     5        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          6        SEND_VAL                                                 'd%2Fm%2FY'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $7      
          9        ASSIGN                                                   !2, $7
   13    10        BOOL_NOT                                         ~9      !2
         11      > JMPNZ_EX                                         ~9      ~9, ->19
         12    >   INIT_FCALL                                               'preg_match'
         13        SEND_VAL                                                 '%2F%28%5B0-9%5D%7B2%7D%29%5C%2F%28%5B0-9%5D%7B2%7D%29%5C%2F%28%5B0-9%5D%7B4%7D%29%2F'
         14        SEND_VAR                                                 !0
         15        SEND_REF                                                 !3
         16        DO_ICALL                                         $10     
         17        BOOL_NOT                                         ~11     $10
         18        BOOL                                             ~9      ~11
         19    > > JMPZ                                                     ~9, ->25
   14    20    >   INIT_METHOD_CALL                                         !1, 'setMessage'
         21        SEND_VAL_EX                                              'Date+is+not+in+the+required+format+DD%2FMM%2FYYYY+%5BPHP+-+d%2Fm%2FY%5D'
         22        DO_FCALL                                      0          
   15    23        VERIFY_RETURN_TYPE                                       !1
         24      > RETURN                                                   !1
   18    25    >   INIT_FCALL                                               'checkdate'
         26        FETCH_DIM_R                                      ~13     !3, 2
         27        CAST                                          4  ~14     ~13
         28        SEND_VAL                                                 ~14
         29        FETCH_DIM_R                                      ~15     !3, 1
         30        CAST                                          4  ~16     ~15
         31        SEND_VAL                                                 ~16
         32        FETCH_DIM_R                                      ~17     !3, 3
         33        CAST                                          4  ~18     ~17
         34        SEND_VAL                                                 ~18
         35        DO_ICALL                                         $19     
         36        BOOL_NOT                                         ~20     $19
         37      > JMPZ                                                     ~20, ->43
   19    38    >   INIT_METHOD_CALL                                         !1, 'setMessage'
         39        SEND_VAL_EX                                              'Date+is+not+valid'
         40        DO_FCALL                                      0          
   20    41        VERIFY_RETURN_TYPE                                       !1
         42      > RETURN                                                   !1
   23    43    >   NEW                                              $22     'DateTime'
         44        DO_FCALL                                      0          
         45        IS_SMALLER                                               $22, !2
         46      > JMPZ                                                     ~24, ->52
   24    47    >   INIT_METHOD_CALL                                         !1, 'setMessage'
         48        SEND_VAL_EX                                              'Date+is+not+historical'
         49        DO_FCALL                                      0          
   25    50        VERIFY_RETURN_TYPE                                       !1
         51      > RETURN                                                   !1
   28    52    >   INIT_METHOD_CALL                                         !1, 'setValidity'
         53        SEND_VAL_EX                                              <true>
         54        DO_FCALL                                      0          
   29    55        VERIFY_RETURN_TYPE                                       !1
         56      > RETURN                                                   !1
   30    57*       VERIFY_RETURN_TYPE                                       
         58*     > RETURN                                                   null

End of function validatehistoricaldate

End of class DateValidator.

Class HistoricalDate:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jh17i
function name:  __construct
number of ops:  5
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        INIT_METHOD_CALL                                         'setDate'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   42     4      > RETURN                                                   null

End of function __construct

Function setvalidity:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jh17i
function name:  setValidity
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   46     1        ASSIGN_OBJ                                               'valid'
          2        OP_DATA                                                  !0
   47     3      > RETURN                                                   null

End of function setvalidity

Function setmessage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jh17i
function name:  setMessage
number of ops:  4
compiled vars:  !0 = $message
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   51     1        ASSIGN_OBJ                                               'message'
          2        OP_DATA                                                  !0
   52     3      > RETURN                                                   null

End of function setmessage

Function isvalid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jh17i
function name:  isValid
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   FETCH_OBJ_R                                      ~0      'valid'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   57     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function isvalid

Function getmessage:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jh17i
function name:  getMessage
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   FETCH_OBJ_R                                      ~0      'message'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   62     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getmessage

Function getdate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jh17i
function name:  getDate
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   FETCH_OBJ_R                                      ~0      'date'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   67     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getdate

Function setdate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jh17i
function name:  setDate
number of ops:  4
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   71     1        ASSIGN_OBJ                                               'date'
          2        OP_DATA                                                  !0
   72     3      > RETURN                                                   null

End of function setdate

End of class HistoricalDate.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
189.99 ms | 1473 KiB | 15 Q