gpt4 book ai didi

php - 在异常中使用 print_r?

转载 作者:行者123 更新时间:2023-12-02 05:27:04 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
putting print_r results in variable

我正在抛出异常并尝试在异常中包含一个变量,如下所示:

throw new Exception('Oh no, an exception! ' . $variable);

(其中 $variable 是一个数组)

问题是,这只会将以下内容放入我的日志文件中:

On no, an exception! Array

不幸的是,我不是 PHP 专家,我猜这可能意味着以下两种情况之一:

1) $variable 是一个空数组

2) $varialbe 是一个数组,里面有数据,但是在异常中输出它并没有输出它的所有内容

如果 1) 是这种情况,请告诉我(但我希望不是)

但是,如果 2) 是这种情况,我如何才能获得有关 $variable 的更多信息?是否可以在异常中执行 print_rvar_dump,如下所示:

throw new Exception('Oh no, an exception! ' . print_r($variable));

或者这会导致问题吗?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com