debug_backtrace是一个bug工具,如果加入到某个类函数里面,那么可以看到调用这个函数的类方法,依次上推,直至index.php
下面是我打印的一个yii2组件的日志:
public function actionBootstrap($app){ $d = debug_backtrace(); foreach($d as $e){ $function = $e['function']; $class = $e['class']; $file = $e['file']; $line = $e['line']; echo $file.'('.$line.'),'. $class.'::'.$function.'()<br/>'; } echo '<br/><br/>';
输出的日志为:
(),fecshop\services\Store::actionBootstrap() /www/web/develop/fecshop/vendor/fancyecommerce/fecshop/services/Service.php(58),::call_user_func_array() /www/web/develop/fecshop/vendor/fancyecommerce/fecshop/components/Store.php(22),fecshop\services\Service::__call() /www/web/develop/fecshop/vendor/fancyecommerce/fecshop/components/Store.php(22),fecshop\services\Store::bootstrap() /www/web/develop/fecshop/vendor/yiisoft/yii2/base/Application.php(316),fecshop\components\Store::bootstrap() /www/web/develop/fecshop/vendor/yiisoft/yii2/web/Application.php(66),yii\base\Application::bootstrap() /www/web/develop/fecshop/vendor/yiisoft/yii2/base/Application.php(267),yii\web\Application::bootstrap() /www/web/develop/fecshop/vendor/yiisoft/yii2/base/Object.php(107),yii\base\Application::init() /www/web/develop/fecshop/vendor/yiisoft/yii2/base/Application.php(206),yii\base\Object::__construct() /www/web/develop/fecshop/appfront/web/index.php(44),yii\base\Application::__construct()
这样就可以记录出来这个函数被调用的位置。