11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP クラス名(インスタンス)からPHPファイルパスに辿り着く方法

Last updated at Posted at 2021-10-08

クラス名(インスタンス)から実際のPHPファイルパスを探したいとき。

public function run($nazoClass)
{
    $nazoClass->nazonazo();
}

$nazoClass ってどこに定義されてるの?を調べます。

環境

IDEのコードジャンプが効かないクソ環境を想定してます。
コードジャンプできればこんなことしなくていいのに...

クラス名を調べる

var_dump(get_class($nazoClass));
die;

ファイルパスを調べる

var_dump((new \ReflectionClass(get_class($nazoClass)))->getFileName());
die;

参考

11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?