它的功能非常强大,我担心它的稳定性和性能.
你怎么看?
UPDATE
我正在做的是这样的:
$old_dir = getcwd();
chdir( dirname($included_file) );
include ( $included_file );
chdir( $old_dir );
Run Code Online (Sandbox Code Playgroud)
基本上它只是这样include ( $included_file );,但在内部$included_file它找不到3.php与它本身位于同一目录中,所以我手动设置cwd并且它工作.但是如果我找到它无法找到的原因会很好至于为什么debug_backtrace需要,因为3.php它被另一个包含func,因为相对路径不起作用,它必须debug_backtrace用来获取包含文件路径,最后使用如下所述的绝对路径.
重现并不容易,因为上面的代码是在一个方法的上下文中,而且还有更多......如果没有其他人遇到过这种问题我想停在这里,无论如何,成本只是额外的3线,没什么大不了的.
有什么方法可以使用debug_backtrace()之外的其他东西来获取调用函数吗?
我正在寻找一种不那么贪婪的方式来模拟朋友或内部的范围.
假设我有A班和B班.
直到现在,我一直在使用debug_backtrace(),这太贪心了(恕我直言).
我想到了这样的事情:
<?php
class A
{
public function __construct(B $callerObj) {}
}
class B
{
public function someMethod()
{
$obj = new A($this);
}
}
?>
Run Code Online (Sandbox Code Playgroud)
如果你想把它限制在一个特定的类,可能没关系,但是假设我有300个类,我想将它限制为25个?
一种方法是使用接口来聚合:
public function __construct(CallerInterface $callerObj)
但它仍然是一个丑陋的代码.
而且,你不能在静态类中使用这个技巧.
有更好的主意吗?
在处理我的一个PHP项目时,我debug_backtrace()在代码文件的开头得到了一个函数<?php debug_backtrace() || die ("Direct access not permitted"); ?>.
在研究它时,我得到了一些解释,它的工作原理是:
在 Drupal 网站中调试 PHP 问题可能是快速和容易的,也可能是严重的问题。PHP 包含一个名为 debug_backtrace 的调试函数,它将打印出直到调用 backtrace 函数的代码链。
当我使用var_dump()withdebug_backtrace()我得到以下结果:
array(2) {
[0]=>
array(3) {
["file"]=>
string(61) "C:\xampp\htdocs\folder_name\templates\default\models\home.php"
["line"]=>
int(30)
["function"]=>
string(7) "include"
}
[1]=>
array(4) {
["file"]=>
string(37) "C:\xampp\htdocs\folder_name\index.php"
["line"]=>
int(146)
["args"]=>
array(1) {
[0]=>
string(61) "C:\xampp\htdocs\folder_name\templates\default\models\home.php"
}
["function"]=>
string(7) "include"
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白什么debug_backtrace()功能完全有效。
请任何人解释是受欢迎的。提前致谢。
学习链接:
我有PHP 5.3.4,当我尝试使用debug_print_backtrace时,我什么都没得到.当我使用vardump时,我得到一个空数组,如下所示.
index.php文件:
<?php
define('WP_USE_THEMES', true);
require('./wp-blog-header.php');
var_dump(debug_backtrace());
echo PHP_VERSION;
?>
Run Code Online (Sandbox Code Playgroud)
返回
...
</html>
array(0) {
}
5.3.4
Run Code Online (Sandbox Code Playgroud)
谁能告诉我有什么问题?我期待看到在运行中调用的所有内容.相反,我没有看到任何东西.