3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Car { protected array $tags; public function __get(string $prop): mixed { 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/ZeZFk
function name:  (null)
number of ops:  12
compiled vars:  !0 = $car, !1 = $carMapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   NEW                                              $2      'Car'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   35     3        ASSIGN_OBJ                                               !0, 'tags'
          4        OP_DATA                                                  <array>
   36     5        NEW                                              $6      'CarMapper'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $6
   37     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 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZeZFk
function name:  __get
number of ops:  11
compiled vars:  !0 = $prop
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'property_exists'
          2        FETCH_THIS                                       ~1      
          3        SEND_VAL                                                 ~1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->9
    9     7    >   FETCH_OBJ_R                                      ~3      !0
          8      > RETURN                                                   ~3
   11     9    >   VERIFY_RETURN_TYPE                                       
         10      > 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/ZeZFk
function name:  __set
number of ops:  11
compiled vars:  !0 = $prop, !1 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     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
   16     8    >   ASSIGN_OBJ                                               !0
          9        OP_DATA                                                  !1
   18    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/ZeZFk
function name:  test
number of ops:  14
compiled vars:  !0 = $car, !1 = $tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     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'
   26     2        INIT_FCALL                                               'var_dump'
          3        ISSET_ISEMPTY_PROP_OBJ                           ~2      !0, 'tags'
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                                 
   28     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'
   29     7        FETCH_OBJ_R                                      ~4      !0, 'tags'
          8        ASSIGN                                                   !1, ~4
   30     9        INIT_FCALL                                               'var_dump'
         10        ISSET_ISEMPTY_CV                                 ~6      !1
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                                 
   31    13      > RETURN                                                   null

End of function test

End of class CarMapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
209.68 ms | 1016 KiB | 15 Q