3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AbstractEvent { protected $id; private $hidden; } final class Event extends AbstractEvent implements JsonSerializable { private $value; public function __construct($id, self $value = null) { $this->id = 5; $this->value = 'abc'; } public function jsonSerialize() { return get_class_vars(); } /** * @param array $data * @return self */ public static function factory(array $data) { $params = []; $constructor = new ReflectionMethod(self::class, '__construct'); foreach ($constructor->getParameters() as $parameter) { $name = $parameter->getName(); $required = !$parameter->isOptional(); echo $parameter->getClass()->name; $params[] = self::getValue($data, $name, $required); } return new self(...$params); } } $e = Event::factory([]); echo json_encode($e);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b2tIh
function name:  (null)
number of ops:  10
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                            'event', 'abstractevent'
   46     1        INIT_STATIC_METHOD_CALL                                  'Event', 'factory'
          2        SEND_VAL_EX                                              <array>
          3        DO_FCALL                                      0  $1      
          4        ASSIGN                                                   !0, $1
   47     5        INIT_FCALL                                               'json_encode'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8        ECHO                                                     $3
          9      > RETURN                                                   1

Class AbstractEvent: [no user functions]
Class Event:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b2tIh
function name:  __construct
number of ops:  7
compiled vars:  !0 = $id, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   16     2        ASSIGN_OBJ                                               'id'
          3        OP_DATA                                                  5
   17     4        ASSIGN_OBJ                                               'value'
          5        OP_DATA                                                  'abc'
   18     6      > RETURN                                                   null

End of function __construct

Function jsonserialize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b2tIh
function name:  jsonSerialize
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'get_class_vars'
          1        DO_ICALL                                         $0      
          2      > RETURN                                                   $0
   23     3*     > RETURN                                                   null

End of function jsonserialize

Function factory:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 30
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/b2tIh
function name:  factory
number of ops:  37
compiled vars:  !0 = $data, !1 = $params, !2 = $constructor, !3 = $parameter, !4 = $name, !5 = $required
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     1        ASSIGN                                                   !1, <array>
   33     2        NEW                                              $7      'ReflectionMethod'
          3        SEND_VAL_EX                                              'Event'
          4        SEND_VAL_EX                                              '__construct'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !2, $7
   34     7        INIT_METHOD_CALL                                         !2, 'getParameters'
          8        DO_FCALL                                      0  $10     
          9      > FE_RESET_R                                       $11     $10, ->30
         10    > > FE_FETCH_R                                               $11, !3, ->30
   35    11    >   INIT_METHOD_CALL                                         !3, 'getName'
         12        DO_FCALL                                      0  $12     
         13        ASSIGN                                                   !4, $12
   36    14        INIT_METHOD_CALL                                         !3, 'isOptional'
         15        DO_FCALL                                      0  $14     
         16        BOOL_NOT                                         ~15     $14
         17        ASSIGN                                                   !5, ~15
   37    18        INIT_METHOD_CALL                                         !3, 'getClass'
         19        DO_FCALL                                      0  $17     
         20        FETCH_OBJ_R                                      ~18     $17, 'name'
         21        ECHO                                                     ~18
   38    22        INIT_STATIC_METHOD_CALL                                  'getValue'
         23        SEND_VAR_EX                                              !0
         24        SEND_VAR_EX                                              !4
         25        SEND_VAR_EX                                              !5
         26        DO_FCALL                                      0  $20     
         27        ASSIGN_DIM                                               !1
         28        OP_DATA                                                  $20
   34    29      > JMP                                                      ->10
         30    >   FE_FREE                                                  $11
   41    31        NEW                          self                $21     
         32        SEND_UNPACK                                              !1
         33        CHECK_UNDEF_ARGS                                         
         34        DO_FCALL                                      1          
         35      > RETURN                                                   $21
   42    36*     > RETURN                                                   null

End of function factory

End of class Event.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.67 ms | 1404 KiB | 17 Q