3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * @template T */ class Example { /** @param T $inner */ public function __construct(public mixed $inner) { } /** * @return T */ public function get(): mixed { return $this->inner; } /** * @template U * @param callable(T): U $callback * @return U */ public function map(callable $callback): mixed { return $callback($this->inner); } /** * @template U * @param callable(T): U $callback * @return Example<U> */ public function chainMap(callable $callback): Example { return new self($callback($this->inner)); } } $example = new Example(123); // phpstorm understands this as int|mixed $value = $example->get(); // phpstorm understands this as int|mixed $value = $example->map(fn (int $val): string => (string) $val); function requiresInt(int $input) { } // phpstorm still sees this more crazy one as int|mixed.. $value = $example->chainMap(fn ($val) => (string) $val) ->chainMap(fn ($val) => new Example($val)) ->chainMap(fn ($val) => new Example($val)) ->chainMap(fn ($val) => $val->get()->get()) ->get(); // but psalm understands // psalm: InvalidScalarArgument: Argument 1 of requiresInt expects int, "123" provided requiresInt($value);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  (null)
number of ops:  35
compiled vars:  !0 = $example, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   NEW                                              $2      'Example'
          1        SEND_VAL_EX                                              123
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   44     4        INIT_METHOD_CALL                                         !0, 'get'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !1, $5
   46     7        INIT_METHOD_CALL                                         !0, 'map'
          8        DECLARE_LAMBDA_FUNCTION                          ~7      [0]
          9        SEND_VAL_EX                                              ~7
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !1, $8
   52    12        INIT_METHOD_CALL                                         !0, 'chainMap'
         13        DECLARE_LAMBDA_FUNCTION                          ~10     [1]
         14        SEND_VAL_EX                                              ~10
         15        DO_FCALL                                      0  $11     
   53    16        INIT_METHOD_CALL                                         $11, 'chainMap'
         17        DECLARE_LAMBDA_FUNCTION                          ~12     [2]
         18        SEND_VAL_EX                                              ~12
         19        DO_FCALL                                      0  $13     
   54    20        INIT_METHOD_CALL                                         $13, 'chainMap'
         21        DECLARE_LAMBDA_FUNCTION                          ~14     [3]
         22        SEND_VAL_EX                                              ~14
         23        DO_FCALL                                      0  $15     
   55    24        INIT_METHOD_CALL                                         $15, 'chainMap'
         25        DECLARE_LAMBDA_FUNCTION                          ~16     [4]
         26        SEND_VAL_EX                                              ~16
         27        DO_FCALL                                      0  $17     
   56    28        INIT_METHOD_CALL                                         $17, 'get'
         29        DO_FCALL                                      0  $18     
   52    30        ASSIGN                                                   !1, $18
   60    31        INIT_FCALL                                               'requiresint'
         32        SEND_VAR                                                 !1
         33        DO_FCALL                                      0          
         34      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        CAST                                          6  ~1      !0
          2        VERIFY_RETURN_TYPE                                       ~1
          3      > RETURN                                                   ~1
          4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        CAST                                          6  ~1      !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        NEW                                              $1      'Example'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
          1        NEW                                              $1      'Example'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of Dynamic Function 3

Dynamic Function 4
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
          1        INIT_METHOD_CALL                                         !0, 'get'
          2        DO_FCALL                                      0  $1      
          3        INIT_METHOD_CALL                                         $1, 'get'
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
          6*     > RETURN                                                   null

End of Dynamic Function 4

Function requiresint:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  requiresInt
number of ops:  2
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
   49     1      > RETURN                                                   null

End of function requiresint

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

End of function __construct

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

End of function get

Function map:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  map
number of ops:  9
compiled vars:  !0 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   28     1        INIT_DYNAMIC_CALL                                        !0
          2        CHECK_FUNC_ARG                                           
          3        FETCH_OBJ_FUNC_ARG                               $1      'inner'
          4        SEND_FUNC_ARG                                            $1
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   29     7*       VERIFY_RETURN_TYPE                                       
          8*     > RETURN                                                   null

End of function map

Function chainmap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlDJZ
function name:  chainMap
number of ops:  13
compiled vars:  !0 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   37     1        NEW                          self                $1      
          2        INIT_DYNAMIC_CALL                                        !0
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $2      'inner'
          5        SEND_FUNC_ARG                                            $2
          6        DO_FCALL                                      0  $3      
          7        SEND_VAR_NO_REF_EX                                       $3
          8        DO_FCALL                                      0          
          9        VERIFY_RETURN_TYPE                                       $1
         10      > RETURN                                                   $1
   38    11*       VERIFY_RETURN_TYPE                                       
         12*     > RETURN                                                   null

End of function chainmap

End of class Example.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.65 ms | 1023 KiB | 14 Q