3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class CommandId { private $name; private $time; private $hash; public function __construct($name) { $this->time = microtime(true); $this->name = trim($name); $this->hash = hash('crc32', rand(0, $this->time)); if (empty($this->name)) { throw new DomainException('Name must not be empty'); } } public static function fromString($idString) { $parts = explode('_', $idString); if (count($parts) != 3) { throw new DomainException("Unexpected format [$idString]"); } $id = new static($parts[0]); $id->time = (float) $parts[1]; $id->hash = $parts[2]; return $id; } public function name() { return $this->name; } public function time() { return $this->time; } public function equals(self $other) { return ( $this->name == $other->name && $this->time == $other->time && $this->hash == $other->hash ); } public function __toString() { return implode('_', [$this->name, $this->time, $this->hash]); } } $one = new CommandId('foo'); $two = CommandId::fromString((string) $one); assert($one->equals($two)); var_dump((string) $one, (string) $two);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23r4P
function name:  (null)
number of ops:  25
compiled vars:  !0 = $one, !1 = $two
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'commandid'
   58     1        NEW                                              $2      'CommandId'
          2        SEND_VAL_EX                                              'foo'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   59     5        INIT_STATIC_METHOD_CALL                                  'CommandId', 'fromString'
          6        CAST                                          6  ~5      !0
          7        SEND_VAL_EX                                              ~5
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !1, $6
   60    10        ASSERT_CHECK                                             
         11        INIT_FCALL                                               'assert'
         12        INIT_METHOD_CALL                                         !0, 'equals'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0  $8      
         15        SEND_VAR                                                 $8
         16        SEND_VAL                                                 'assert%28%24one-%3Eequals%28%24two%29%29'
         17        DO_ICALL                                                 
   62    18        INIT_FCALL                                               'var_dump'
         19        CAST                                          6  ~10     !0
         20        SEND_VAL                                                 ~10
         21        CAST                                          6  ~11     !1
         22        SEND_VAL                                                 ~11
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Class CommandId:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23r4P
function name:  __construct
number of ops:  29
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'microtime'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $2      
          4        ASSIGN_OBJ                                               'time'
          5        OP_DATA                                                  $2
   12     6        INIT_FCALL                                               'trim'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $4      
          9        ASSIGN_OBJ                                               'name'
         10        OP_DATA                                                  $4
   13    11        INIT_FCALL                                               'hash'
         12        SEND_VAL                                                 'crc32'
         13        INIT_FCALL                                               'rand'
         14        SEND_VAL                                                 0
         15        FETCH_OBJ_R                                      ~6      'time'
         16        SEND_VAL                                                 ~6
         17        DO_ICALL                                         $7      
         18        SEND_VAR                                                 $7
         19        DO_ICALL                                         $8      
         20        ASSIGN_OBJ                                               'hash'
         21        OP_DATA                                                  $8
   15    22        ISSET_ISEMPTY_PROP_OBJ                                   'name'
         23      > JMPZ                                                     ~9, ->28
   16    24    >   NEW                                              $10     'DomainException'
         25        SEND_VAL_EX                                              'Name+must+not+be+empty'
         26        DO_FCALL                                      0          
         27      > THROW                                         0          $10
   18    28    > > RETURN                                                   null

End of function __construct

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

End of function fromstring

Function name:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/23r4P
function name:  name
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
   36     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/23r4P
function name:  time
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   FETCH_OBJ_R                                      ~0      'time'
          1      > RETURN                                                   ~0
   41     2*     > RETURN                                                   null

End of function time

Function equals:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 9
filename:       /in/23r4P
function name:  equals
number of ops:  16
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   46     1        FETCH_OBJ_R                                      ~1      'name'
          2        FETCH_OBJ_R                                      ~2      !0, 'name'
          3        IS_EQUAL                                         ~3      ~1, ~2
          4      > JMPZ_EX                                          ~3      ~3, ->9
   47     5    >   FETCH_OBJ_R                                      ~4      'time'
          6        FETCH_OBJ_R                                      ~5      !0, 'time'
          7        IS_EQUAL                                         ~6      ~4, ~5
          8        BOOL                                             ~3      ~6
          9    > > JMPZ_EX                                          ~3      ~3, ->14
   48    10    >   FETCH_OBJ_R                                      ~7      'hash'
         11        FETCH_OBJ_R                                      ~8      !0, 'hash'
         12        IS_EQUAL                                         ~9      ~7, ~8
         13        BOOL                                             ~3      ~9
         14    > > RETURN                                                   ~3
   50    15*     > 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/23r4P
function name:  __toString
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   INIT_FCALL                                               'implode'
          1        SEND_VAL                                                 '_'
          2        FETCH_OBJ_R                                      ~0      'name'
          3        INIT_ARRAY                                       ~1      ~0
          4        FETCH_OBJ_R                                      ~2      'time'
          5        ADD_ARRAY_ELEMENT                                ~1      ~2
          6        FETCH_OBJ_R                                      ~3      'hash'
          7        ADD_ARRAY_ELEMENT                                ~1      ~3
          8        SEND_VAL                                                 ~1
          9        DO_ICALL                                         $4      
         10        VERIFY_RETURN_TYPE                                       $4
         11      > RETURN                                                   $4
   55    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function __tostring

End of class CommandId.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.66 ms | 1408 KiB | 29 Q