3v4l.org

run code in 500+ PHP versions simultaneously
<?php //型を厳密にする declare(strict_types=1); class GameCharacter { //プロパティ private string $name; //名前 private int $level; //レベル private int $atttack; //攻撃力 private int $defense; //防御力 //コンストラクタ public function __construct(string $name, int $attack, int $defense) { //自分のクラスのプロパティは$thisという変数を使う $this ->name = $name; $this ->level = 1; $this ->attack = $attack; $this ->defense = $defense; } //メソッド(レベルアップ) //レベルアップすると攻撃力と防御力がランダム値上昇する public function levelUp(): void { //自分のクラスのメソッドにアクセスするには$thisを使う $this->level++; $this->attackUp(); $this->defenseUp(); } //メソッド(ステータス表示) public function echoStatus(): void { echo "{$this->name}はレベル{$this->level}で、攻撃力:{$this->attack}, 防御力:{$this->defense}\n"; } private function getRandomValue(): int { //<< 疑似乱数を生成する組み込み関数 //1から10のランダムの値を返す return random_int(1,10); } private function attackUp(): void { $up = $this->getRandomValue(); $this->attack += $up; echo "{$this->name}の攻撃力は{$up}上がった\n"; } private function defenseUp():void { $up = $this->getRandomValue(); $this->defense += $up; echo "{$this->name}の防御力は{$up}上がった\n"; } } $taro = new GameCharacter("Taro", 100, 90); // GameCharacterクラスをインスタンス化(実体化) $jiro = new GameCharacter("Jiro", 80, 110); // GameCharacterクラスをインスタンス化(実体化) $taro->levelUp(); //メソッド呼び出し $jiro->levelUp(); //メソッド呼び出し $taro->echoStatus(); $jiro->echoStatus(); //$taro->getRandomValue(); //privateメソッドのアクセスはエラー ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kKJpV
function name:  (null)
number of ops:  21
compiled vars:  !0 = $taro, !1 = $jiro
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   54     0  E >   NEW                                                  $2      'GameCharacter'
          1        SEND_VAL_EX                                                  'Taro'
          2        SEND_VAL_EX                                                  100
          3        SEND_VAL_EX                                                  90
          4        DO_FCALL                                          0          
          5        ASSIGN                                                       !0, $2
   55     6        NEW                                                  $5      'GameCharacter'
          7        SEND_VAL_EX                                                  'Jiro'
          8        SEND_VAL_EX                                                  80
          9        SEND_VAL_EX                                                  110
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !1, $5
   56    12        INIT_METHOD_CALL                                             !0, 'levelUp'
         13        DO_FCALL                                          0          
   57    14        INIT_METHOD_CALL                                             !1, 'levelUp'
         15        DO_FCALL                                          0          
   58    16        INIT_METHOD_CALL                                             !0, 'echoStatus'
         17        DO_FCALL                                          0          
   59    18        INIT_METHOD_CALL                                             !1, 'echoStatus'
         19        DO_FCALL                                          0          
   61    20      > RETURN                                                       1

Class GameCharacter:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kKJpV
function name:  __construct
number of ops:  12
compiled vars:  !0 = $name, !1 = $attack, !2 = $defense
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   15     3        ASSIGN_OBJ                                                   'name'
          4        OP_DATA                                                      !0
   16     5        ASSIGN_OBJ                                                   'level'
          6        OP_DATA                                                      1
   17     7        ASSIGN_OBJ                                                   'attack'
          8        OP_DATA                                                      !1
   18     9        ASSIGN_OBJ                                                   'defense'
         10        OP_DATA                                                      !2
   19    11      > RETURN                                                       null

End of function __construct

Function levelup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kKJpV
function name:  levelUp
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   PRE_INC_OBJ                                                  'level'
   26     1        INIT_METHOD_CALL                                             'attackUp'
          2        DO_FCALL                                          0          
   27     3        INIT_METHOD_CALL                                             'defenseUp'
          4        DO_FCALL                                          0          
   28     5      > RETURN                                                       null

End of function levelup

Function echostatus:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kKJpV
function name:  echoStatus
number of ops:  14
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   FETCH_OBJ_R                                          ~0      'name'
          1        ROPE_INIT                                         8  ~5      ~0
          2        ROPE_ADD                                          1  ~5      ~5, '%E3%81%AF%E3%83%AC%E3%83%99%E3%83%AB'
          3        FETCH_OBJ_R                                          ~1      'level'
          4        ROPE_ADD                                          2  ~5      ~5, ~1
          5        ROPE_ADD                                          3  ~5      ~5, '%E3%81%A7%E3%80%81%E6%94%BB%E6%92%83%E5%8A%9B%EF%BC%9A'
          6        FETCH_OBJ_R                                          ~2      'attack'
          7        ROPE_ADD                                          4  ~5      ~5, ~2
          8        ROPE_ADD                                          5  ~5      ~5, '%2C+%E9%98%B2%E5%BE%A1%E5%8A%9B%3A'
          9        FETCH_OBJ_R                                          ~3      'defense'
         10        ROPE_ADD                                          6  ~5      ~5, ~3
         11        ROPE_END                                          7  ~4      ~5, '%0A'
         12        ECHO                                                         ~4
   33    13      > RETURN                                                       null

End of function echostatus

Function getrandomvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kKJpV
function name:  getRandomValue
number of ops:  8
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                                   'random_int'
          1        SEND_VAL                                                     1
          2        SEND_VAL                                                     10
          3        DO_ICALL                                             $0      
          4        VERIFY_RETURN_TYPE                                           $0
          5      > RETURN                                                       $0
   39     6*       VERIFY_RETURN_TYPE                                           
          7*     > RETURN                                                       null

End of function getrandomvalue

Function attackup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kKJpV
function name:  attackUp
number of ops:  12
compiled vars:  !0 = $up
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   42     0  E >   INIT_METHOD_CALL                                             'getRandomValue'
          1        DO_FCALL                                          0  $1      
          2        ASSIGN                                                       !0, $1
   43     3        ASSIGN_OBJ_OP                                     1          'attack'
          4        OP_DATA                                                      !0
   44     5        FETCH_OBJ_R                                          ~4      'name'
          6        ROPE_INIT                                         4  ~6      ~4
          7        ROPE_ADD                                          1  ~6      ~6, '%E3%81%AE%E6%94%BB%E6%92%83%E5%8A%9B%E3%81%AF'
          8        ROPE_ADD                                          2  ~6      ~6, !0
          9        ROPE_END                                          3  ~5      ~6, '%E4%B8%8A%E3%81%8C%E3%81%A3%E3%81%9F%0A'
         10        ECHO                                                         ~5
   45    11      > RETURN                                                       null

End of function attackup

Function defenseup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kKJpV
function name:  defenseUp
number of ops:  12
compiled vars:  !0 = $up
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   48     0  E >   INIT_METHOD_CALL                                             'getRandomValue'
          1        DO_FCALL                                          0  $1      
          2        ASSIGN                                                       !0, $1
   49     3        ASSIGN_OBJ_OP                                     1          'defense'
          4        OP_DATA                                                      !0
   50     5        FETCH_OBJ_R                                          ~4      'name'
          6        ROPE_INIT                                         4  ~6      ~4
          7        ROPE_ADD                                          1  ~6      ~6, '%E3%81%AE%E9%98%B2%E5%BE%A1%E5%8A%9B%E3%81%AF'
          8        ROPE_ADD                                          2  ~6      ~6, !0
          9        ROPE_END                                          3  ~5      ~6, '%E4%B8%8A%E3%81%8C%E3%81%A3%E3%81%9F%0A'
         10        ECHO                                                         ~5
   51    11      > RETURN                                                       null

End of function defenseup

End of class GameCharacter.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
128.43 ms | 891 KiB | 10 Q