3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Maybe { private function __construct(private mixed $value = null) {} public static function Some(mixed $v): static { return new static($v); } public function value(): mixed { return null === $this->value ? throw new Exception() : $this->value; } public function __invoke(callable $c): static { return null===$this->value ? $this : static::Some($c($this->value)); } } function double($x) { return $x * 2; } $res = Maybe::Some(30) (double::class) (chr::class) (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/7lUI0M
function name:  (null)
number of ops:  20
compiled vars:  !0 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_STATIC_METHOD_CALL                                  'Maybe', 'Some'
          1        SEND_VAL                                                 30
          2        DO_FCALL                                      0  $1      
          3        INIT_DYNAMIC_CALL                                        $1
   30     4        SEND_VAL_EX                                              'double'
          5        DO_FCALL                                      0  $2      
          6        INIT_DYNAMIC_CALL                                        $2
   31     7        SEND_VAL_EX                                              'chr'
          8        DO_FCALL                                      0  $3      
          9        INIT_DYNAMIC_CALL                                        $3
   32    10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F7lUI0M%3A32%240'
         11        SEND_VAL_EX                                              ~4
         12        DO_FCALL                                      0  $5      
   29    13        ASSIGN                                                   !0, $5
   34    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/7lUI0M
function name:  double
number of ops:  4
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        MUL                                              ~1      !0, 2
          2      > RETURN                                                   ~1
   26     3*     > RETURN                                                   null

End of function double

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

End of function %00%7Bclosure%7D%2Fin%2F7lUI0M%3A32%240

Class Maybe:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7lUI0M
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 some:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7lUI0M
function name:  Some
number of ops:  8
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        NEW                          static              $1      
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        VERIFY_RETURN_TYPE                                       $1
          5      > RETURN                                                   $1
    9     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 = 43) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7lUI0M
function name:  value
number of ops:  13
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~0      'value'
          1        TYPE_CHECK                                    2          ~0
          2      > JMPZ                                                     ~1, ->8
   13     3    >   NEW                                              $2      'Exception'
          4        DO_FCALL                                      0          
          5      > THROW                                         1          $2
          6*       QM_ASSIGN                                        ~4      <true>
          7*       JMP                                                      ->10
   14     8    >   FETCH_OBJ_R                                      ~5      'value'
          9        QM_ASSIGN                                        ~4      ~5
         10      > RETURN                                                   ~4
   15    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function value

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

End of function __invoke

End of class Maybe.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.45 ms | 1409 KiB | 15 Q