提问人:neubert 提问时间:5/23/2023 更新时间:5/23/2023 访问量:36
为什么子类不能覆盖父类的“__debugInfo”?
Why isn't child class able to overwrite `__debugInfo` of parent class?
问:
这是我的代码:
use Carbon\Carbon;
class Demo extends Carbon
{
public function __debugInfo(): array
{
return ['value' => $this->__toString()];
}
}
$d = new Demo();
print_r($d);
我所期望的输出是这样的:
Demo Object
(
[value] => 2023-05-23 13:57:18
)
但我得到的是:
Demo Object
(
[endOfTime:protected] =>
[startOfTime:protected] =>
[constructedObjectId:protected] => 00000000000000020000000000000000
[localMonthsOverflow:protected] =>
[localYearsOverflow:protected] =>
[localStrictModeEnabled:protected] =>
[localHumanDiffOptions:protected] =>
[localToStringFormat:protected] =>
[localSerializer:protected] =>
[localMacros:protected] =>
[localGenericMacros:protected] =>
[localFormatFunction:protected] =>
[localTranslator:protected] =>
[dumpProperties:protected] => Array
(
[0] => date
[1] => timezone_type
[2] => timezone
)
[dumpLocale:protected] =>
[dumpDateProperties:protected] =>
[date] => 2023-05-23 13:57:18.314578
[timezone_type] => 3
[timezone] => UTC
)
有什么想法吗?
答: 暂无答案
评论
: array
__debugInfo
仅适用于(对于任何对象,而不仅仅是子类或 Carbon 对象)var_dump()