开发者

In PHP code, given an object, is it possible to locate the source file?

开发者 https://www.devze.com 2023-02-10 09:42 出处:网络
Within a PHP class that is part of a much larger system, the full extent of which is not readily known, is it possible to find out where the source code resides for an object that is known to my code?

Within a PHP class that is part of a much larger system, the full extent of which is not readily known, is it possible to find out where the source code resides for an object that is known to my code? That is, I have a variable that is loaded with an object about which I do not know much. Given that variable, is there a way to know what source f开发者_StackOverflow社区ile to look in to find the source code for the object that is in my variable?


Sure is.

<?php
class Test {
}

$test = new Test;
$reflect = new ReflectionClass(get_class($test));
echo $reflect->getFileName();
0

精彩评论

暂无评论...
验证码 换一张
取 消