3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MessageId { protected static $partSeperator = '_'; protected static $hashAlgorithm = 'crc32'; protected static $validNames = ['foo']; protected $name; protected $time; protected $hash; public function __construct($name) { $this->time = microtime(true); $this->name = trim($name); $this->hash = hash(static::$hashAlgorithm, rand(0, $this->time)); if (empty($this->name)) { throw new DomainException('Name must not be empty'); } if (!in_array($this->name, static::$validNames)) { throw new DomainException("Invalid name [$name]"); } } public static function fromString($idString) { $parts = explode(static::$partSeperator, $idString); if (count($parts) != 3) { throw new DomainException("Unexpected format [$idString]"); } return static::fromParts($parts[0], $parts[1], $parts[2]); } public static function fromParts($name, $time, $hash) { $id = new static($name); $id->time = floatval($time); $id->hash = strval($hash); return $id; } public function name() { return $this->name; } public function time() { return $this->time; } public function equals(self $other) { return ((string) $this == (string) $other); } public function __toString() { return implode(static::$partSeperator, (array) $this); } } $foo = new MessageId('foo'); var_dump((string) $foo);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZvOX
function name:  (null)
number of ops:  10
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'messageid'
   65     1        NEW                                              $1      'MessageId'
          2        SEND_VAL_EX                                              'foo'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   66     5        INIT_FCALL                                               'var_dump'
          6        CAST                                          6  ~4      !0
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Class MessageId:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 44
Branch analysis from position: 37
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZvOX
function name:  __construct
number of ops:  45
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               'time'
          5        OP_DATA                                                  $2
   15     6        INIT_FCALL                                               'trim'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $4      
          9        ASSIGN_OBJ                                               'name'
         10        OP_DATA                                                  $4
   16    11        INIT_FCALL                                               'hash'
         12        FETCH_STATIC_PROP_R          unknown             ~6      'hashAlgorithm'
         13        SEND_VAL                                                 ~6
         14        INIT_FCALL                                               'rand'
         15        SEND_VAL                                                 0
         16        FETCH_OBJ_R                                      ~7      'time'
         17        SEND_VAL                                                 ~7
         18        DO_ICALL                                         $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                         $9      
         21        ASSIGN_OBJ                                               'hash'
         22        OP_DATA                                                  $9
   18    23        ISSET_ISEMPTY_PROP_OBJ                                   'name'
         24      > JMPZ                                                     ~10, ->29
   19    25    >   NEW                                              $11     'DomainException'
         26        SEND_VAL_EX                                              'Name+must+not+be+empty'
         27        DO_FCALL                                      0          
         28      > THROW                                         0          $11
   21    29    >   INIT_FCALL                                               'in_array'
         30        FETCH_OBJ_R                                      ~13     'name'
         31        SEND_VAL                                                 ~13
         32        FETCH_STATIC_PROP_R          unknown             ~14     'validNames'
         33        SEND_VAL                                                 ~14
         34        DO_ICALL                                         $15     
         35        BOOL_NOT                                         ~16     $15
         36      > JMPZ                                                     ~16, ->44
   22    37    >   NEW                                              $17     'DomainException'
         38        ROPE_INIT                                     3  ~19     'Invalid+name+%5B'
         39        ROPE_ADD                                      1  ~19     ~19, !0
         40        ROPE_END                                      2  ~18     ~19, '%5D'
         41        SEND_VAL_EX                                              ~18
         42        DO_FCALL                                      0          
         43      > THROW                                         0          $17
   24    44    > > RETURN                                                   null

End of function __construct

Function fromstring:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZvOX
function name:  fromString
number of ops:  30
compiled vars:  !0 = $idString, !1 = $parts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        INIT_FCALL                                               'explode'
          2        FETCH_STATIC_PROP_R          global lock         ~2      'partSeperator'
          3        SEND_VAL                                                 ~2
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        ASSIGN                                                   !1, $3
   29     7        COUNT                                            ~5      !1
          8        IS_NOT_EQUAL                                             ~5, 3
          9      > JMPZ                                                     ~6, ->17
   30    10    >   NEW                                              $7      'DomainException'
         11        ROPE_INIT                                     3  ~9      'Unexpected+format+%5B'
         12        ROPE_ADD                                      1  ~9      ~9, !0
         13        ROPE_END                                      2  ~8      ~9, '%5D'
         14        SEND_VAL_EX                                              ~8
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $7
   32    17    >   INIT_STATIC_METHOD_CALL                                  'fromParts'
         18        CHECK_FUNC_ARG                                           
         19        FETCH_DIM_FUNC_ARG                               $12     !1, 0
         20        SEND_FUNC_ARG                                            $12
         21        CHECK_FUNC_ARG                                           
         22        FETCH_DIM_FUNC_ARG                               $13     !1, 1
         23        SEND_FUNC_ARG                                            $13
         24        CHECK_FUNC_ARG                                           
         25        FETCH_DIM_FUNC_ARG                               $14     !1, 2
         26        SEND_FUNC_ARG                                            $14
         27        DO_FCALL                                      0  $15     
         28      > RETURN                                                   $15
   33    29*     > RETURN                                                   null

End of function fromstring

Function fromparts:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZvOX
function name:  fromParts
number of ops:  15
compiled vars:  !0 = $name, !1 = $time, !2 = $hash, !3 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   37     3        NEW                          static              $4      
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !3, $4
   38     7        CAST                                          5  ~8      !1
          8        ASSIGN_OBJ                                               !3, 'time'
          9        OP_DATA                                                  ~8
   39    10        CAST                                          6  ~10     !2
         11        ASSIGN_OBJ                                               !3, 'hash'
         12        OP_DATA                                                  ~10
   41    13      > RETURN                                                   !3
   42    14*     > RETURN                                                   null

End of function fromparts

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

End of function name

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

End of function time

Function equals:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZvOX
function name:  equals
number of ops:  7
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        FETCH_THIS                                       ~1      
          2        CAST                                          6  ~2      ~1
          3        CAST                                          6  ~3      !0
          4        IS_EQUAL                                         ~4      ~2, ~3
          5      > RETURN                                                   ~4
   57     6*     > RETURN                                                   null

End of function equals

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TZvOX
function name:  __toString
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_FCALL                                               'implode'
          1        FETCH_STATIC_PROP_R          global lock         ~0      'partSeperator'
          2        SEND_VAL                                                 ~0
          3        FETCH_THIS                                       ~1      
          4        CAST                                          7  ~2      ~1
          5        SEND_VAL                                                 ~2
          6        DO_ICALL                                         $3      
          7        VERIFY_RETURN_TYPE                                       $3
          8      > RETURN                                                   $3
   62     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function __tostring

End of class MessageId.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.9 ms | 1408 KiB | 29 Q