3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CanCastBool extends SimpleXMLElement { /** @var WeakMap 各 CanCastBool インスタンスのプロパティを保持する WeakMap */ public static WeakMap $properties; /** * XML を意識しないコンストラクタ * @param string $fuga * @return CanCastBool */ public static function makeInstance(string $fuga): CanCastBool { $instance = new self('<bool></bool>'); $instance->true = true; self::$properties ??= new WeakMap(); // WeakMap に自分をキーにしてプロパティを記録させる // WeakMap に退避させておくので XML とは別の扱いになる self::$properties[$instance] = [ 'fuga' => $fuga, ]; return $instance; } /** プロパティ的に読み取るメソッド。WeakMap から取ってくる */ public function getP(string $name) { return self::$properties[$this][$name]; } /** プロパティ的にセットするメソッド。WeakMap にセットする */ public function setP($name, $value) { self::$properties[$this][$name] = $value; } public function toTrue(): void { $this->true = true; } public function toFalse(): void { unset($this->true); } } $a = CanCastBool::makeInstance('fugafuga'); $b = CanCastBool::makeInstance('piyopiyo'); echo "---init----\n"; var_dump((bool)$a);// true var_dump($a->getP('fuga'));// 'fugafuga' $a->setP('fuga', 'foo'); $a->setP('hoge', 'bar'); echo "----------\n"; $a->toFalse(); var_dump((bool)$a);// false var_dump($a->getP('fuga'));// 'foo' var_dump($a->getP('hoge'));// 'bar' $a->setP('hoge', 'hogehoge'); echo "----------\n"; $a->toTrue(); var_dump((bool)$a);// true var_dump($a->getP('fuga'));// 'foo' var_dump($a->getP('hoge'));// 'hogehoge' var_dump($b->getP('fuga'));// 'piyopiyo'
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kBnZJ
function name:  (null)
number of ops:  76
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   INIT_STATIC_METHOD_CALL                                  'CanCastBool', 'makeInstance'
          1        SEND_VAL                                                 'fugafuga'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
   52     4        INIT_STATIC_METHOD_CALL                                  'CanCastBool', 'makeInstance'
          5        SEND_VAL                                                 'piyopiyo'
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !1, $4
   54     8        ECHO                                                     '---init----%0A'
   55     9        INIT_FCALL                                               'var_dump'
         10        BOOL                                             ~6      !0
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                                 
   56    13        INIT_FCALL                                               'var_dump'
         14        INIT_METHOD_CALL                                         !0, 'getP'
         15        SEND_VAL_EX                                              'fuga'
         16        DO_FCALL                                      0  $8      
         17        SEND_VAR                                                 $8
         18        DO_ICALL                                                 
   57    19        INIT_METHOD_CALL                                         !0, 'setP'
         20        SEND_VAL_EX                                              'fuga'
         21        SEND_VAL_EX                                              'foo'
         22        DO_FCALL                                      0          
   58    23        INIT_METHOD_CALL                                         !0, 'setP'
         24        SEND_VAL_EX                                              'hoge'
         25        SEND_VAL_EX                                              'bar'
         26        DO_FCALL                                      0          
   60    27        ECHO                                                     '----------%0A'
   61    28        INIT_METHOD_CALL                                         !0, 'toFalse'
         29        DO_FCALL                                      0          
   62    30        INIT_FCALL                                               'var_dump'
         31        BOOL                                             ~13     !0
         32        SEND_VAL                                                 ~13
         33        DO_ICALL                                                 
   63    34        INIT_FCALL                                               'var_dump'
         35        INIT_METHOD_CALL                                         !0, 'getP'
         36        SEND_VAL_EX                                              'fuga'
         37        DO_FCALL                                      0  $15     
         38        SEND_VAR                                                 $15
         39        DO_ICALL                                                 
   64    40        INIT_FCALL                                               'var_dump'
         41        INIT_METHOD_CALL                                         !0, 'getP'
         42        SEND_VAL_EX                                              'hoge'
         43        DO_FCALL                                      0  $17     
         44        SEND_VAR                                                 $17
         45        DO_ICALL                                                 
   65    46        INIT_METHOD_CALL                                         !0, 'setP'
         47        SEND_VAL_EX                                              'hoge'
         48        SEND_VAL_EX                                              'hogehoge'
         49        DO_FCALL                                      0          
   67    50        ECHO                                                     '----------%0A'
   68    51        INIT_METHOD_CALL                                         !0, 'toTrue'
         52        DO_FCALL                                      0          
   69    53        INIT_FCALL                                               'var_dump'
         54        BOOL                                             ~21     !0
         55        SEND_VAL                                                 ~21
         56        DO_ICALL                                                 
   70    57        INIT_FCALL                                               'var_dump'
         58        INIT_METHOD_CALL                                         !0, 'getP'
         59        SEND_VAL_EX                                              'fuga'
         60        DO_FCALL                                      0  $23     
         61        SEND_VAR                                                 $23
         62        DO_ICALL                                                 
   71    63        INIT_FCALL                                               'var_dump'
         64        INIT_METHOD_CALL                                         !0, 'getP'
         65        SEND_VAL_EX                                              'hoge'
         66        DO_FCALL                                      0  $25     
         67        SEND_VAR                                                 $25
         68        DO_ICALL                                                 
   73    69        INIT_FCALL                                               'var_dump'
         70        INIT_METHOD_CALL                                         !1, 'getP'
         71        SEND_VAL_EX                                              'fuga'
         72        DO_FCALL                                      0  $27     
         73        SEND_VAR                                                 $27
         74        DO_ICALL                                                 
         75      > RETURN                                                   1

Class CanCastBool:
Function makeinstance:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kBnZJ
function name:  makeInstance
number of ops:  23
compiled vars:  !0 = $fuga, !1 = $instance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        NEW                          self                $2      
          2        SEND_VAL_EX                                              '%3Cbool%3E%3C%2Fbool%3E'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
   16     5        ASSIGN_OBJ                                               !1, 'true'
          6        OP_DATA                                                  <true>
   18     7        FETCH_STATIC_PROP_IS                             ~6      'properties'
          8        COALESCE                                         ~7      ~6
          9        NEW                                              $8      'WeakMap'
         10        DO_FCALL                                      0          
         11        ASSIGN_STATIC_PROP                               ~10     'properties'
         12        OP_DATA                                                  $8
         13        QM_ASSIGN                                        ~7      ~10
         14        FREE                                                     ~7
   22    15        INIT_ARRAY                                       ~13     !0, 'fuga'
   21    16        FETCH_STATIC_PROP_W          unknown             $11     'properties'
         17        ASSIGN_DIM                                               $11, !1
   22    18        OP_DATA                                                  ~13
   25    19        VERIFY_RETURN_TYPE                                       !1
         20      > RETURN                                                   !1
   26    21*       VERIFY_RETURN_TYPE                                       
         22*     > RETURN                                                   null

End of function makeinstance

Function getp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kBnZJ
function name:  getP
number of ops:  7
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     1        FETCH_THIS                                       ~2      
          2        FETCH_STATIC_PROP_R          unknown             ~1      'properties'
          3        FETCH_DIM_R                                      ~3      ~1, ~2
          4        FETCH_DIM_R                                      ~4      ~3, !0
          5      > RETURN                                                   ~4
   32     6*     > RETURN                                                   null

End of function getp

Function setp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kBnZJ
function name:  setP
number of ops:  8
compiled vars:  !0 = $name, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2        FETCH_THIS                                       ~3      
          3        FETCH_STATIC_PROP_W          global              $2      'properties'
          4        FETCH_DIM_W                                      $4      $2, ~3
          5        ASSIGN_DIM                                               $4, !0
          6        OP_DATA                                                  !1
   38     7      > RETURN                                                   null

End of function setp

Function totrue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kBnZJ
function name:  toTrue
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   ASSIGN_OBJ                                               'true'
          1        OP_DATA                                                  <true>
   44     2      > RETURN                                                   null

End of function totrue

Function tofalse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kBnZJ
function name:  toFalse
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   UNSET_OBJ                                                'true'
   48     1      > RETURN                                                   null

End of function tofalse

End of class CanCastBool.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.52 ms | 1458 KiB | 14 Q