3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Car { protected array $tags; public function __get(string $prop): mixed { print("__get($prop) called"); if (property_exists($this, $prop)) { return $this->{$prop}; } } public function __set(string $prop, mixed $val): void { if (property_exists($this, $prop)) { $this->$prop = $val; } } } class CarMapper { public function test(Car $car): void { echo 'そのままだとtrueになる'.PHP_EOL; var_dump(empty($car->tags)); // bool(true) echo '代入するとfalseになる'.PHP_EOL; $tags = $car->tags; var_dump(empty($tags)); // bool(false) } } $car = new Car(); $car->tags = ['tag1']; $carMapper = new CarMapper(); $carMapper->test($car);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rquRC
function name:  (null)
number of ops:  12
compiled vars:  !0 = $car, !1 = $carMapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   NEW                                              $2      'Car'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   36     3        ASSIGN_OBJ                                               !0, 'tags'
          4        OP_DATA                                                  <array>
   37     5        NEW                                              $6      'CarMapper'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $6
   38     8        INIT_METHOD_CALL                                         !1, 'test'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
         11      > RETURN                                                   1

Class Car:
Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rquRC
function name:  __get
number of ops:  15
compiled vars:  !0 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        ROPE_INIT                                     3  ~2      '__get%28'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%29+called'
          4        ECHO                                                     ~1
    9     5        INIT_FCALL                                               'property_exists'
          6        FETCH_THIS                                       ~4      
          7        SEND_VAL                                                 ~4
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $5      
         10      > JMPZ                                                     $5, ->13
   10    11    >   FETCH_OBJ_R                                      ~6      !0
         12      > RETURN                                                   ~6
   12    13    >   VERIFY_RETURN_TYPE                                       
         14      > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/rquRC
function name:  __set
number of ops:  11
compiled vars:  !0 = $prop, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2        INIT_FCALL                                               'property_exists'
          3        FETCH_THIS                                       ~2      
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7      > JMPZ                                                     $3, ->10
   17     8    >   ASSIGN_OBJ                                               !0
          9        OP_DATA                                                  !1
   19    10    > > RETURN                                                   null

End of function __set

End of class Car.

Class CarMapper:
Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rquRC
function name:  test
number of ops:  14
compiled vars:  !0 = $car, !1 = $tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        ECHO                                                     '%E3%81%9D%E3%81%AE%E3%81%BE%E3%81%BE%E3%81%A0%E3%81%A8true%E3%81%AB%E3%81%AA%E3%82%8B%0A'
   27     2        INIT_FCALL                                               'var_dump'
          3        ISSET_ISEMPTY_PROP_OBJ                           ~2      !0, 'tags'
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                                 
   29     6        ECHO                                                     '%E4%BB%A3%E5%85%A5%E3%81%99%E3%82%8B%E3%81%A8false%E3%81%AB%E3%81%AA%E3%82%8B%0A'
   30     7        FETCH_OBJ_R                                      ~4      !0, 'tags'
          8        ASSIGN                                                   !1, ~4
   31     9        INIT_FCALL                                               'var_dump'
         10        ISSET_ISEMPTY_CV                                 ~6      !1
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                                 
   32    13      > RETURN                                                   null

End of function test

End of class CarMapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
205.3 ms | 1016 KiB | 15 Q