3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Maybe { private function __construct(private mixed $value = null) {} public static function None(): static { return new static(null); } public static function Some(mixed $v): static { return new static($v); } public function value(): mixed { return match ($this->value) { null => throw new Exception(), default => $this->value, }; } public function __invoke(callable $c): static { return match ($this->value) { null => $this, default => static::Some($c($this->value)), }; } } function double($x) { return $x * 2; } $res = Maybe::Some(30) ('double') ('chr') (fn($x) => strlen($x)); var_dump($res->value());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TLUvB
function name:  (null)
number of ops:  20
compiled vars:  !0 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_STATIC_METHOD_CALL                                  'Maybe', 'Some'
          1        SEND_VAL                                                 30
          2        DO_FCALL                                      0  $1      
          3        INIT_DYNAMIC_CALL                                        $1
   36     4        SEND_VAL_EX                                              'double'
          5        DO_FCALL                                      0  $2      
          6        INIT_DYNAMIC_CALL                                        $2
   37     7        SEND_VAL_EX                                              'chr'
          8        DO_FCALL                                      0  $3      
          9        INIT_DYNAMIC_CALL                                        $3
   38    10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FTLUvB%3A38%240'
         11        SEND_VAL_EX                                              ~4
         12        DO_FCALL                                      0  $5      
   35    13        ASSIGN                                                   !0, $5
   40    14        INIT_FCALL                                               'var_dump'
         15        INIT_METHOD_CALL                                         !0, 'value'
         16        DO_FCALL                                      0  $7      
         17        SEND_VAR                                                 $7
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Function double:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TLUvB
function name:  double
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        MUL                                              ~1      !0, 2
          2      > RETURN                                                   ~1
   32     3*     > RETURN                                                   null

End of function double

Function %00%7Bclosure%7D%2Fin%2FTLUvB%3A38%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TLUvB
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        STRLEN                                           ~1      !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FTLUvB%3A38%240

Class Maybe:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TLUvB
function name:  __construct
number of ops:  4
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV_INIT                                        !0      null
          1        ASSIGN_OBJ                                               'value'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function __construct

Function none:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TLUvB
function name:  None
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   NEW                          static              $0      
          1        SEND_VAL_EX                                              null
          2        DO_FCALL                                      0          
          3        VERIFY_RETURN_TYPE                                       $0
          4      > RETURN                                                   $0
    9     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function none

Function some:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TLUvB
function name:  Some
number of ops:  8
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        NEW                          static              $1      
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
   13     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function some

Function value:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/TLUvB
function name:  value
number of ops:  16
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        CASE_STRICT                                              ~0, null
          2      > JMPNZ                                                    ~1, ->4
          3    > > JMP                                                      ->9
   17     4    >   NEW                                              $2      'Exception'
          5        DO_FCALL                                      0          
          6      > THROW                                         1          $2
          7*       QM_ASSIGN                                        ~4      <true>
          8*       JMP                                                      ->12
   18     9    >   FETCH_OBJ_R                                      ~5      'value'
         10        QM_ASSIGN                                        ~4      ~5
         11      > JMP                                                      ->12
         12    >   FREE                                                     ~0
         13      > RETURN                                                   ~4
   20    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function value

Function __invoke:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
filename:       /in/TLUvB
function name:  __invoke
number of ops:  23
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        FETCH_OBJ_R                                      ~1      'value'
          2        CASE_STRICT                                              ~1, null
          3      > JMPNZ                                                    ~2, ->5
          4    > > JMP                                                      ->8
   24     5    >   FETCH_THIS                                       ~3      
          6        QM_ASSIGN                                        ~4      ~3
          7      > JMP                                                      ->18
   25     8    >   INIT_STATIC_METHOD_CALL                                  'Some'
          9        INIT_DYNAMIC_CALL                                        !0
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $5      'value'
         12        SEND_FUNC_ARG                                            $5
         13        DO_FCALL                                      0  $6      
         14        SEND_VAR_NO_REF_EX                                       $6
         15        DO_FCALL                                      0  $7      
         16        QM_ASSIGN                                        ~4      $7
         17      > JMP                                                      ->18
         18    >   FREE                                                     ~1
         19        VERIFY_RETURN_TYPE                                       ~4
         20      > RETURN                                                   ~4
   27    21*       VERIFY_RETURN_TYPE                                       
         22*     > RETURN                                                   null

End of function __invoke

End of class Maybe.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
129.4 ms | 1409 KiB | 15 Q