お世話になってます。表題の件で値が取得できず困っております。。
環境はPHP5.4/Codeigniter3 です。
例外クラスを独自追加して、throwさせているのですが、プロパティがprotectedになっており、
エラーコードやメッセージが取得できません。。
PHP
1# libraries/Api_response.php (独自追加) 2class Api_Response extends Exception{ 3 public function __construct($msg, $code){ 4 parent::__construct($msg, $code); 5 } 6} 7 8class UpdateException extends Api_Response{ 9 public function __construct($error){ 10 parent::__construct("error has occured !!!", 3020); 11 } 12} 13 14 15# Controller 16require APPPATH.'libraries/Api_Response.php'; 17・・・ 18throw new UpdateException(); 19・・・ 20・・・ 21try{ 22・・・ 23} catch(UpdateException $e){ 24 $response = ['error' => ['code' => $e->getCode]]; # Undefined property: UpdateException::$getCode となってしまう。 25} 26 27 28# codeigniterのログ (print_rで$e の中身を出力) 29StatusUpdateException Object 30( 31 [message:protected] => Update Database has failed. 32 [string:Exception:private] => 33 [code:protected] => 3020 34 [file:protected] => /var/www/html/xxxxxx 35 [line:protected] => 156 36 [trace:Exception:private] 37# protectedとなっている。 38...
おおむね上記のようなコードですが(分かり難くてすみません。。)、$e
の中身がprotectedであるためか$e->getCode
で値が取り出せずUndefined property
となってしまいます。
throwしているところはpublic内です。
基本的な部分が分かっていない為かと思いますが、何かお気づきになられた箇所があれば、教えていただきたいです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/18 11:26