前提・実現したいこと
定数に対して型を明示的に指定できないのでしょうか?
現状は定数を使用して比較しようとするとプログラムが止まってしまいます。
定数ではなく、メンバ変数として宣言してコンストラクタで代入するのが定石なのでしょうか?
以下のように指定したいです。
PHP
1public const string directorActivityHash_GLASS = '1888320892';
発生している問題・エラーメッセージ
Fatal error: Uncaught Error: Undefined constant "directorActivityHash_GLASS" in C:\xampp\htdocs\Destiny2\raid\lib\RaidReport.php:41 Stack trace: #0 C:\xampp\htdocs\Destiny2\raid\raid.php(32): RaidReport->getRaidReport('1888320892', 'NihonNo_Roma4mi...') #1 C:\xampp\htdocs\Destiny2\raid\raid.php(257): CreateRaidTable('4726149', '1888320892') #2 {main} thrown in C:\xampp\htdocs\Destiny2\raid\lib\RaidReport.php on line 41
該当のソースコード
PHP
1<?php 2class RaidReport 3{ 4 // 定数 5 public const directorActivityHash_GLASS = '1888320892'; 6 public const directorActivityHash_DEEP = '541780856'; 7 public const directorActivityHash_GARDEN = '2712317338'; 8 public const directorActivityHash_WISH = '3181387331'; 9 10 // メンバ変数 11 public $profile; 12 public $raidCompleted1; 13 public $raidCompleted2; 14 public $raidCompleted3; 15 public $raidPhaseCompleted1; 16 public $raidPhaseCompleted2; 17 public $raidPhaseCompleted3; 18 public $raidPhaseCnt; 19 private $BungieAPI; 20 21 // コンストラクタ 22 public function __construct($instanceBungieAPI) 23 { 24 require_once 'BungieProfileAPI.php'; 25 $this->raidCompleted1 = false; 26 $this->raidCompleted2 = false; 27 $this->raidCompleted3 = false; 28 $this->raidPhaseCompleted1 = array(); 29 $this->raidPhaseCompleted2 = array(); 30 $this->raidPhaseCompleted3 = array(); 31 $this->raidPhaseCnt = 0; 32 $this->profile = new BungieProfileAPI($instanceBungieAPI); 33 $this->BungieAPI = $instanceBungieAPI; 34 } 35 36 // アカウントのレイドデータ取得 37 public function getRaidReport($raidKind, $BungieName) 38 { 39 // ★☆★☆★☆★☆★☆★☆★☆ 40 // ここで処理が止まる 41 // ★☆★☆★☆★☆★☆★☆★☆ 42 switch ($raidKind) 43 { 44 case this::directorActivityHash_GLASS: 45 case this::directorActivityHash_DEEP: 46 case this::directorActivityHash_WISH: 47 $this->raidPhaseCnt = 5; 48 break; 49 case this::directorActivityHash_GARDEN: 50 $this->raidPhaseCnt = 1; 51 break; 52 } 53 54 // プロフィール取得 55 if (!$this->profile->getProfile($BungieName)) 56 { 57 return false; 58 } 59 60 // レイド進捗取得 61 $json = $this->profile->getProfileWithComponents('202'); 62 if ($json == null) 63 { 64 return false; 65 } 66} 67 ?> 68
試したこと
補足情報(FW/ツールのバージョンなど)
PHP Version 8.0.10

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2021/10/22 11:25