3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class CommandId { private $name; private $time; private $hash; public function __construct($name, $time = null, $hash = null) { $this->time = floatval($time ?: microtime(true)); $this->name = trim($name); $this->hash = strval($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]"); } return new static($parts[0], $parts[1], $parts[2]); } 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('_', [$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/8U321
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'
   50     1        NEW                                              $2      'CommandId'
          2        SEND_VAL_EX                                              'foo'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   51     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
   52    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 = 32, Position 2 = 36
Branch analysis from position: 32
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8U321
function name:  __construct
number of ops:  37
compiled vars:  !0 = $name, !1 = $time, !2 = $hash
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
   11     3        JMP_SET                                          ~4      !1, ->8
          4        INIT_FCALL                                               'microtime'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $5      
          7        QM_ASSIGN                                        ~4      $5
          8        CAST                                          5  ~6      ~4
          9        ASSIGN_OBJ                                               'time'
         10        OP_DATA                                                  ~6
   12    11        INIT_FCALL                                               'trim'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $8      
         14        ASSIGN_OBJ                                               'name'
         15        OP_DATA                                                  $8
   13    16        JMP_SET                                          ~10     !2, ->27
         17        INIT_FCALL                                               'hash'
         18        SEND_VAL                                                 'crc32'
         19        INIT_FCALL                                               'rand'
         20        SEND_VAL                                                 0
         21        FETCH_OBJ_R                                      ~11     'time'
         22        SEND_VAL                                                 ~11
         23        DO_ICALL                                         $12     
         24        SEND_VAR                                                 $12
         25        DO_ICALL                                         $13     
         26        QM_ASSIGN                                        ~10     $13
         27        CAST                                          6  ~14     ~10
         28        ASSIGN_OBJ                                               'hash'
         29        OP_DATA                                                  ~14
   15    30        ISSET_ISEMPTY_PROP_OBJ                                   'name'
         31      > JMPZ                                                     ~15, ->36
   16    32    >   NEW                                              $16     'DomainException'
         33        SEND_VAL_EX                                              'Name+must+not+be+empty'
         34        DO_FCALL                                      0          
         35      > THROW                                         0          $16
   18    36    > > 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/8U321
function name:  fromString
number of ops:  29
compiled vars:  !0 = $idString, !1 = $parts
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                                         $2      
          5        ASSIGN                                                   !1, $2
   23     6        COUNT                                            ~4      !1
          7        IS_NOT_EQUAL                                             ~4, 3
          8      > JMPZ                                                     ~5, ->16
   24     9    >   NEW                                              $6      'DomainException'
         10        ROPE_INIT                                     3  ~8      'Unexpected+format+%5B'
         11        ROPE_ADD                                      1  ~8      ~8, !0
         12        ROPE_END                                      2  ~7      ~8, '%5D'
         13        SEND_VAL_EX                                              ~7
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $6
   26    16    >   NEW                          static              $11     
         17        CHECK_FUNC_ARG                                           
         18        FETCH_DIM_FUNC_ARG                               $12     !1, 0
         19        SEND_FUNC_ARG                                            $12
         20        CHECK_FUNC_ARG                                           
         21        FETCH_DIM_FUNC_ARG                               $13     !1, 1
         22        SEND_FUNC_ARG                                            $13
         23        CHECK_FUNC_ARG                                           
         24        FETCH_DIM_FUNC_ARG                               $14     !1, 2
         25        SEND_FUNC_ARG                                            $14
         26        DO_FCALL                                      0          
         27      > RETURN                                                   $11
   27    28*     > 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/8U321
function name:  name
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1      > RETURN                                                   ~0
   32     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/8U321
function name:  time
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   FETCH_OBJ_R                                      ~0      'time'
          1      > RETURN                                                   ~0
   37     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/8U321
function name:  equals
number of ops:  7
compiled vars:  !0 = $other
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        FETCH_THIS                                       ~1      
          2        CAST                                          6  ~2      ~1
          3        CAST                                          6  ~3      !0
          4        IS_EQUAL                                         ~4      ~2, ~3
          5      > RETURN                                                   ~4
   42     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/8U321
function name:  __toString
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     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
   47    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:
153.24 ms | 1408 KiB | 27 Q