简体   繁体   English

查找包含类的文件(基于__autoload),但不要包含它

[英]Find a file containing a class (based on __autoload), but don't include it

I am using Composer to load PHP dependencies. 我正在使用Composer加载PHP依赖项。 Given the name of the class I want to find path of the file where this class is defined, but don't include it. 给定类的名称,我想找到定义该类的文件的路径,但不要包括它。

Example: 例:

echo get_file_for_class('Carbon\\Carbon');

Output: 输出:

vendor/briannesbitt/Carbon/src/Carbon/Carbon.php

Thanks! 谢谢!

You could use the Reflection Class. 您可以使用反射类。 http://php.net/manual/en/class.reflectionclass.php http://php.net/manual/zh/class.reflectionclass.php

$reflector = new ReflectionClass('Carbon\\Carbon');
echo $reflector->getFileName();

There are some additional useful class methods you could also play around with, to determine its parent, if it inherits from one, or its start line. 您还可以使用一些其他有用的类方法来确定其父级(如果它是从其继承的)或其起始行。

$reflector->getParentClass();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM