且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

print_r() 向 DateTime 对象添加属性

更新时间:2023-12-02 22:23:04

发生了一些神奇的事情,但很简单.

There is some magic occurring but it's pretty simple.

DateTime 类没有您使用的公共变量日期"意在访问.但是,作为 PHP 工作方式的一个副作用,当您对该类调用 print_r 或 var_dump 时会创建一个变量.

The class DateTime doesn't have a public variable 'date' that you're meant to access. However, as a side effect of how PHP works, there is a variable created when you call print_r or var_dump on that class.

在那魔法发生后,日期"可用,但不应该.您应该只使用 getTimestamp 函数来使您的代码可靠地工作.

After that magic happens 'date' is available, but it shouldn't be. You should just use the getTimestamp function to make your code work reliably.