3v4l.org

run code in 300+ PHP versions simultaneously
<?php class EventStatus { const SUCCESS = 'success'; const STOPPED = 'stopped'; const FAILED = 'failed'; private static $validStatuses = [ self::SUCCESS, self::STOPPED, self::FAILED ]; private $status = self::SUCCESS; public function __construct($aStatus = self::SUCCESS) { $this->status = $this->sanitizeAndValidate($aStatus); } public static function __callStatic($aStatus, $arguments = []) { return new static($aStatus); } public function isSuccess() { return ($this->status == static::SUCCESS); } public function isStopped() { return ($this->status == static::STOPPED); } public function isFailed() { return ($this->status == static::FAILED); } private function sanitize($aStatus) { return strtolower(trim($aStatus)); } private function validate($aStatus) { if (!in_array($aStatus, static::$validStatuses)) { throw new DomainException("Invalid event status [$aStatus]"); } } private function sanitizeAndValidate($aStatus) { $sanitized = $this->sanitize($aStatus); $this->validate($sanitized); return $sanitized; } } $status = EventStatus::Failed(); var_dump($status, $status->isSuccess());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  (null)
number of ops:  10
compiled vars:  !0 = $status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   INIT_STATIC_METHOD_CALL                                  'EventStatus', 'Failed'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   63     3        INIT_FCALL                                               'var_dump'
          4        SEND_VAR                                                 !0
          5        INIT_METHOD_CALL                                         !0, 'isSuccess'
          6        DO_FCALL                                      0  $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Class EventStatus:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  __construct
number of ops:  7
compiled vars:  !0 = $aStatus
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV_INIT                                        !0      <const ast>
   19     1        INIT_METHOD_CALL                                         'sanitizeAndValidate'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN_OBJ                                               'status'
          5        OP_DATA                                                  $2
   20     6      > RETURN                                                   null

End of function __construct

Function __callstatic:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  __callStatic
number of ops:  7
compiled vars:  !0 = $aStatus, !1 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   24     2        NEW                          static              $2      
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5      > RETURN                                                   $2
   25     6*     > RETURN                                                   null

End of function __callstatic

Function issuccess:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  isSuccess
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        FETCH_CLASS_CONSTANT                             ~1      'SUCCESS'
          2        IS_EQUAL                                         ~2      ~0, ~1
          3      > RETURN                                                   ~2
   30     4*     > RETURN                                                   null

End of function issuccess

Function isstopped:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  isStopped
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        FETCH_CLASS_CONSTANT                             ~1      'STOPPED'
          2        IS_EQUAL                                         ~2      ~0, ~1
          3      > RETURN                                                   ~2
   35     4*     > RETURN                                                   null

End of function isstopped

Function isfailed:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  isFailed
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_OBJ_R                                      ~0      'status'
          1        FETCH_CLASS_CONSTANT                             ~1      'FAILED'
          2        IS_EQUAL                                         ~2      ~0, ~1
          3      > RETURN                                                   ~2
   40     4*     > RETURN                                                   null

End of function isfailed

Function sanitize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  sanitize
number of ops:  9
compiled vars:  !0 = $aStatus
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
   44     1        INIT_FCALL                                               'strtolower'
          2        INIT_FCALL                                               'trim'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
   45     8*     > RETURN                                                   null

End of function sanitize

Function validate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  validate
number of ops:  16
compiled vars:  !0 = $aStatus
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1        INIT_FCALL                                               'in_array'
          2        SEND_VAR                                                 !0
          3        FETCH_STATIC_PROP_R          global lock         ~1      'validStatuses'
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        BOOL_NOT                                         ~3      $2
          7      > JMPZ                                                     ~3, ->15
   50     8    >   NEW                                              $4      'DomainException'
          9        ROPE_INIT                                     3  ~6      'Invalid+event+status+%5B'
         10        ROPE_ADD                                      1  ~6      ~6, !0
         11        ROPE_END                                      2  ~5      ~6, '%5D'
         12        SEND_VAL_EX                                              ~5
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $4
   52    15    > > RETURN                                                   null

End of function validate

Function sanitizeandvalidate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iaT52
function name:  sanitizeAndValidate
number of ops:  10
compiled vars:  !0 = $aStatus, !1 = $sanitized
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        INIT_METHOD_CALL                                         'sanitize'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   57     5        INIT_METHOD_CALL                                         'validate'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0          
   58     8      > RETURN                                                   !1
   59     9*     > RETURN                                                   null

End of function sanitizeandvalidate

End of class EventStatus.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.86 ms | 1404 KiB | 21 Q