3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Hash { protected $algo; private $bytes; protected $data; public function __construct(string $data) { $this->bytes = strlen(hash($this->algo, '', true)); $this->data = $data; } public function getRaw() : string { return $this->value; } public function getHex() : string { return bin2hex($this->value); } public function getBase64() : string { return base64_encode($this->value); } public static function fromHex(string $data) : Hash { return new static(hex2bin($data)); } public static function fromBase64(string $data) : Hash { return new static(base64_decode($data)); } public static function getClass(string $algo) : string { $prefix = ucfirst(strtolower($algo)); $class = implode('\\', [__NAMESPACE__, "${prefix}Hash"]); return $class; } } final class Md5Hash extends Hash { protected $algo = 'md5'; } final class Sha256Hash extends Hash { protected $algo = 'sha256'; } final class Sha512Hash extends Hash { protected $algo = 'sha512'; } foreach(explode('|', 'md5|sha256|sha512') as $a){ $submitted[$a] = hash($a, 'foobar'); } foreach($submitted as $algo => $hexVal){ $hashes[] = (Hash::getClass($algo))::fromHex($hexVal); } var_dump($hashes);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 13
filename:       /in/AJqOl
function name:  (null)
number of ops:  32
compiled vars:  !0 = $a, !1 = $submitted, !2 = $hexVal, !3 = $algo, !4 = $hashes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   INIT_FCALL                                               'explode'
          1        SEND_VAL                                                 '%7C'
          2        SEND_VAL                                                 'md5%7Csha256%7Csha512'
          3        DO_ICALL                                         $5      
          4      > FE_RESET_R                                       $6      $5, ->13
          5    > > FE_FETCH_R                                               $6, !0, ->13
   54     6    >   INIT_FCALL                                               'hash'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'foobar'
          9        DO_ICALL                                         $8      
         10        ASSIGN_DIM                                               !1, !0
         11        OP_DATA                                                  $8
   53    12      > JMP                                                      ->5
         13    >   FE_FREE                                                  $6
   57    14      > FE_RESET_R                                       $9      !1, ->27
         15    > > FE_FETCH_R                                       ~10     $9, !2, ->27
         16    >   ASSIGN                                                   !3, ~10
   58    17        INIT_STATIC_METHOD_CALL                                  'Hash', 'getClass'
         18        SEND_VAR                                                 !3
         19        DO_FCALL                                      0  $13     
         20        FETCH_CLASS                                   0  $14     $13
         21        INIT_STATIC_METHOD_CALL                                  $14, 'fromHex'
         22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0  $15     
         24        ASSIGN_DIM                                               !4
         25        OP_DATA                                                  $15
   57    26      > JMP                                                      ->15
         27    >   FE_FREE                                                  $9
   61    28        INIT_FCALL                                               'var_dump'
         29        SEND_VAR                                                 !4
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Class Hash:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  __construct
number of ops:  13
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'hash'
          2        FETCH_OBJ_R                                      ~2      'algo'
          3        SEND_VAL                                                 ~2
          4        SEND_VAL                                                 ''
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $3      
          7        STRLEN                                           ~4      $3
          8        ASSIGN_OBJ                                               'bytes'
          9        OP_DATA                                                  ~4
   13    10        ASSIGN_OBJ                                               'data'
         11        OP_DATA                                                  !0
   14    12      > RETURN                                                   null

End of function __construct

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

End of function getraw

Function gethex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getHex
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'bin2hex'
          1        FETCH_OBJ_R                                      ~0      'value'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   24     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function gethex

Function getbase64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getBase64
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'base64_encode'
          1        FETCH_OBJ_R                                      ~0      'value'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   29     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function getbase64

Function fromhex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  fromHex
number of ops:  11
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1        NEW                          static              $1      
          2        INIT_FCALL                                               'hex2bin'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7        VERIFY_RETURN_TYPE                                       $1
          8      > RETURN                                                   $1
   34     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function fromhex

Function frombase64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  fromBase64
number of ops:  11
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        NEW                          static              $1      
          2        INIT_FCALL                                               'base64_decode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7        VERIFY_RETURN_TYPE                                       $1
          8      > RETURN                                                   $1
   39     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function frombase64

Function getclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getClass
number of ops:  21
compiled vars:  !0 = $algo, !1 = $prefix, !2 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'ucfirst'
          2        INIT_FCALL                                               'strtolower'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        SEND_VAR                                                 $3
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   44     8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '%5C'
         10        INIT_ARRAY                                       ~6      ''
         11        NOP                                                      
         12        FAST_CONCAT                                      ~7      !1, 'Hash'
         13        ADD_ARRAY_ELEMENT                                ~6      ~7
         14        SEND_VAL                                                 ~6
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !2, $8
   45    17        VERIFY_RETURN_TYPE                                       !2
         18      > RETURN                                                   !2
   46    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function getclass

End of class Hash.

Class Md5Hash:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  __construct
number of ops:  13
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'hash'
          2        FETCH_OBJ_R                                      ~2      'algo'
          3        SEND_VAL                                                 ~2
          4        SEND_VAL                                                 ''
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $3      
          7        STRLEN                                           ~4      $3
          8        ASSIGN_OBJ                                               'bytes'
          9        OP_DATA                                                  ~4
   13    10        ASSIGN_OBJ                                               'data'
         11        OP_DATA                                                  !0
   14    12      > RETURN                                                   null

End of function __construct

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

End of function getraw

Function gethex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getHex
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'bin2hex'
          1        FETCH_OBJ_R                                      ~0      'value'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   24     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function gethex

Function getbase64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getBase64
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'base64_encode'
          1        FETCH_OBJ_R                                      ~0      'value'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   29     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function getbase64

Function fromhex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  fromHex
number of ops:  11
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1        NEW                          static              $1      
          2        INIT_FCALL                                               'hex2bin'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7        VERIFY_RETURN_TYPE                                       $1
          8      > RETURN                                                   $1
   34     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function fromhex

Function frombase64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  fromBase64
number of ops:  11
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        NEW                          static              $1      
          2        INIT_FCALL                                               'base64_decode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7        VERIFY_RETURN_TYPE                                       $1
          8      > RETURN                                                   $1
   39     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function frombase64

Function getclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getClass
number of ops:  21
compiled vars:  !0 = $algo, !1 = $prefix, !2 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'ucfirst'
          2        INIT_FCALL                                               'strtolower'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        SEND_VAR                                                 $3
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   44     8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '%5C'
         10        INIT_ARRAY                                       ~6      ''
         11        NOP                                                      
         12        FAST_CONCAT                                      ~7      !1, 'Hash'
         13        ADD_ARRAY_ELEMENT                                ~6      ~7
         14        SEND_VAL                                                 ~6
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !2, $8
   45    17        VERIFY_RETURN_TYPE                                       !2
         18      > RETURN                                                   !2
   46    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function getclass

End of class Md5Hash.

Class Sha256Hash:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  __construct
number of ops:  13
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'hash'
          2        FETCH_OBJ_R                                      ~2      'algo'
          3        SEND_VAL                                                 ~2
          4        SEND_VAL                                                 ''
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $3      
          7        STRLEN                                           ~4      $3
          8        ASSIGN_OBJ                                               'bytes'
          9        OP_DATA                                                  ~4
   13    10        ASSIGN_OBJ                                               'data'
         11        OP_DATA                                                  !0
   14    12      > RETURN                                                   null

End of function __construct

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

End of function getraw

Function gethex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getHex
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   INIT_FCALL                                               'bin2hex'
          1        FETCH_OBJ_R                                      ~0      'value'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   24     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function gethex

Function getbase64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getBase64
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'base64_encode'
          1        FETCH_OBJ_R                                      ~0      'value'
          2        SEND_VAL                                                 ~0
          3        DO_ICALL                                         $1      
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   29     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function getbase64

Function fromhex:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  fromHex
number of ops:  11
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1        NEW                          static              $1      
          2        INIT_FCALL                                               'hex2bin'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7        VERIFY_RETURN_TYPE                                       $1
          8      > RETURN                                                   $1
   34     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function fromhex

Function frombase64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  fromBase64
number of ops:  11
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        NEW                          static              $1      
          2        INIT_FCALL                                               'base64_decode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7        VERIFY_RETURN_TYPE                                       $1
          8      > RETURN                                                   $1
   39     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function frombase64

Function getclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getClass
number of ops:  21
compiled vars:  !0 = $algo, !1 = $prefix, !2 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   43     1        INIT_FCALL                                               'ucfirst'
          2        INIT_FCALL                                               'strtolower'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        SEND_VAR                                                 $3
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   44     8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '%5C'
         10        INIT_ARRAY                                       ~6      ''
         11        NOP                                                      
         12        FAST_CONCAT                                      ~7      !1, 'Hash'
         13        ADD_ARRAY_ELEMENT                                ~6      ~7
         14        SEND_VAL                                                 ~6
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !2, $8
   45    17        VERIFY_RETURN_TYPE                                       !2
         18      > RETURN                                                   !2
   46    19*       VERIFY_RETURN_TYPE                                       
         20*     > RETURN                                                   null

End of function getclass

End of class Sha256Hash.

Class Sha512Hash:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  __construct
number of ops:  13
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'hash'
          2        FETCH_OBJ_R                                      ~2      'algo'
          3        SEND_VAL                                                 ~2
          4        SEND_VAL                                                 ''
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                         $3      
          7        STRLEN                                           ~4      $3
          8        ASSIGN_OBJ                                               'bytes'
          9        OP_DATA                                                  ~4
   13    10        ASSIGN_OBJ                                               'data'
         11        OP_DATA                                                  !0
   14    12      > RETURN                                                   null

End of function __construct

Function getraw:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AJqOl
function name:  getRaw
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18  

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.9 ms | 1428 KiB | 33 Q