3v4l.org

run code in 300+ PHP versions simultaneously
<?php Class Driver { private $cars; public function __construct() { $this->cars = new \stdClass(); foreach (Car::$all_cars as $car) { $this->cars->$car = NULL; } } public function setRating($car, $rating) { $this->cars->$car = $rating; } public function __get($car) { return property_exists($this->cars, $car) ? $this->cars->$car : null; } } Class Car { public static $all_cars = array(); private $name; public function __construct($name) { $this->name = $name; self::$all_cars[] = $this; } public function __toString() { return $this->name; } } $bmw = new Car('bmw'); $benz = new Car('benz'); $tom = new Driver; $tom->setRating($bmw, 95); $tom->setRating($benz, 97); echo $tom->bmw; // 95
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TjC89
function name:  (null)
number of ops:  23
compiled vars:  !0 = $bmw, !1 = $benz, !2 = $tom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   DECLARE_CLASS                                            'car'
   35     1        NEW                                              $3      'Car'
          2        SEND_VAL_EX                                              'bmw'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   36     5        NEW                                              $6      'Car'
          6        SEND_VAL_EX                                              'benz'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   38     9        NEW                                              $9      'Driver'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $9
   39    12        INIT_METHOD_CALL                                         !2, 'setRating'
         13        SEND_VAR_EX                                              !0
         14        SEND_VAL_EX                                              95
         15        DO_FCALL                                      0          
   40    16        INIT_METHOD_CALL                                         !2, 'setRating'
         17        SEND_VAR_EX                                              !1
         18        SEND_VAL_EX                                              97
         19        DO_FCALL                                      0          
   42    20        FETCH_OBJ_R                                      ~14     !2, 'bmw'
         21        ECHO                                                     ~14
         22      > RETURN                                                   1

Class Driver:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/TjC89
function name:  __construct
number of ops:  13
compiled vars:  !0 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   NEW                                              $2      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'cars'
          3        OP_DATA                                                  $2
    8     4        FETCH_STATIC_PROP_R          unknown             ~4      'all_cars'
          5      > FE_RESET_R                                       $5      ~4, ->11
          6    > > FE_FETCH_R                                               $5, !0, ->11
    9     7    >   FETCH_OBJ_W                                      $6      'cars'
          8        ASSIGN_OBJ                                               $6, !0
          9        OP_DATA                                                  null
    8    10      > JMP                                                      ->6
         11    >   FE_FREE                                                  $5
   11    12      > RETURN                                                   null

End of function __construct

Function setrating:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TjC89
function name:  setRating
number of ops:  6
compiled vars:  !0 = $car, !1 = $rating
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2        FETCH_OBJ_W                                      $2      'cars'
          3        ASSIGN_OBJ                                               $2, !0
          4        OP_DATA                                                  !1
   14     5      > RETURN                                                   null

End of function setrating

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
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: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TjC89
function name:  __get
number of ops:  14
compiled vars:  !0 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        INIT_FCALL                                               'property_exists'
          2        FETCH_OBJ_R                                      ~1      'cars'
          3        SEND_VAL                                                 ~1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->11
          7    >   FETCH_OBJ_R                                      ~3      'cars'
          8        FETCH_OBJ_R                                      ~4      ~3, !0
          9        QM_ASSIGN                                        ~5      ~4
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~5      null
         12    > > RETURN                                                   ~5
   17    13*     > RETURN                                                   null

End of function __get

End of class Driver.

Class Car:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TjC89
function name:  __construct
number of ops:  8
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
   27     3        FETCH_THIS                                       ~4      
          4        FETCH_STATIC_PROP_W          unknown             $2      'all_cars'
          5        ASSIGN_DIM                                               $2
          6        OP_DATA                                                  ~4
   28     7      > RETURN                                                   null

End of function __construct

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

End of function __tostring

End of class Car.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.61 ms | 1019 KiB | 14 Q