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 = floatval($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 == $other); } public function __toString() { return implode('_', [$this->name, $this->time, $this->hash]); } } $one = new CommandId('foo'); $two = CommandId::fromString((string) $one); var_dump($one, $two, $one->equals($two));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iPpGt
function name:  (null)
number of ops:  19
compiled vars:  !0 = $one, !1 = $two
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'commandid'
   54     1        NEW                                              $2      'CommandId'
          2        SEND_VAL_EX                                              'foo'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   55     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
   56    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        INIT_METHOD_CALL                                         !0, 'equals'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $8      
         16        SEND_VAR                                                 $8
         17        DO_ICALL                                                 
         18      > 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/iPpGt
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/iPpGt
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/iPpGt
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/iPpGt
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iPpGt
function name:  equals
number of ops:  5
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   45     1        FETCH_THIS                                       ~1      
          2        IS_EQUAL                                         ~2      !0, ~1
          3      > RETURN                                                   ~2
   46     4*     > 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/iPpGt
function name:  __toString
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     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
   51    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:
152.96 ms | 1404 KiB | 27 Q