3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Point { public readonly string $name; public function __construct( public readonly int $x, public readonly int $y, ) {} public function setName(string $name): static { $this->name ??= $name; return $this; } } $p = new Point(3, 4); $p->setName('Larry'); var_dump($p); $rClass = new \ReflectionClass(Point::class); $new = $rClass->newInstanceWithoutConstructor(); $setter = (fn (string $k, mixed $v) => $this->$k = $v)->bindTo($new, $new); $setter('x', 3); $setter('y', 4); $setter('name', 'Larry'); var_dump($new);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vKnVo
function name:  (null)
number of ops:  40
compiled vars:  !0 = $p, !1 = $rClass, !2 = $new, !3 = $setter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $4      'Point'
          1        SEND_VAL_EX                                              3
          2        SEND_VAL_EX                                              4
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $4
   21     5        INIT_METHOD_CALL                                         !0, 'setName'
          6        SEND_VAL_EX                                              'Larry'
          7        DO_FCALL                                      0          
   23     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
   25    11        NEW                                              $9      'ReflectionClass'
         12        SEND_VAL_EX                                              'Point'
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !1, $9
   26    15        INIT_METHOD_CALL                                         !1, 'newInstanceWithoutConstructor'
         16        DO_FCALL                                      0  $12     
         17        ASSIGN                                                   !2, $12
   28    18        DECLARE_LAMBDA_FUNCTION                          ~14     [0]
         19        INIT_METHOD_CALL                                         ~14, 'bindTo'
         20        SEND_VAR_EX                                              !2
         21        SEND_VAR_EX                                              !2
         22        DO_FCALL                                      0  $15     
         23        ASSIGN                                                   !3, $15
   30    24        INIT_DYNAMIC_CALL                                        !3
         25        SEND_VAL_EX                                              'x'
         26        SEND_VAL_EX                                              3
         27        DO_FCALL                                      0          
   31    28        INIT_DYNAMIC_CALL                                        !3
         29        SEND_VAL_EX                                              'y'
         30        SEND_VAL_EX                                              4
         31        DO_FCALL                                      0          
   32    32        INIT_DYNAMIC_CALL                                        !3
         33        SEND_VAL_EX                                              'name'
         34        SEND_VAL_EX                                              'Larry'
         35        DO_FCALL                                      0          
   35    36        INIT_FCALL                                               'var_dump'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                                 
         39      > 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/vKnVo
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $k, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        FETCH_THIS                                       $2      
          3        ASSIGN_OBJ                                       ~3      $2, !0
          4        OP_DATA                                                  !1
          5      > RETURN                                                   ~3
          6*     > RETURN                                                   null

End of Dynamic Function 0

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

End of function __construct

Function setname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vKnVo
function name:  setName
number of ops:  12
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   14     1        FETCH_OBJ_IS                                     ~1      'name'
          2        COALESCE                                         ~2      ~1
          3        ASSIGN_OBJ                                       ~3      'name'
          4        OP_DATA                                                  !0
          5        QM_ASSIGN                                        ~2      ~3
          6        FREE                                                     ~2
   15     7        FETCH_THIS                                       ~4      
          8        VERIFY_RETURN_TYPE                                       ~4
          9      > RETURN                                                   ~4
   16    10*       VERIFY_RETURN_TYPE                                       
         11*     > RETURN                                                   null

End of function setname

End of class Point.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
316.49 ms | 1005 KiB | 15 Q