Skip to content

リファクタリング提案その1 #1

@pm-yosuke

Description

@pm-yosuke

/**
* Return a list of constants.
*
* @return array Constant list
* @throws ReflectionException
*/
static function getConstants() {
$oClass = new ReflectionClass( __CLASS__ );
return $oClass->getConstants();
}

プロダクトのコードでリフレクションは使用しないほうが良いかと。
理由として、

  1. 普通に配列を作る場合と比べて、 15倍 以上遅くなる
  2. @throws にあるとおり、例外が発生する可能性を無駄に増やす
  3. 71〜77、86〜92行目でこんだけ列挙してるなら115行目で同じように全て列挙しても変わらんよね

※私の経験上、リフレクションは基本的にデバッグやテスト用と割り切ったほうが良いかと思います。

Metadata

Metadata

Assignees

Labels

wontfixThis will not be worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions