【发布时间】:2021-05-19 19:36:54
【问题描述】:
如果我在某个班级使用var_dump,请说DateTime:
<?php
$date = new DateTime();
var_dump($date);
我明白了
/var/www/php/test/index.php:5:
object(DateTime)[1]
public 'date' => string '2021-02-16 23:23:10.768097' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/Berlin' (length=13)
我认为有 3 个公共属性。所以我尝试访问它们:
<?php
$date = new DateTime();
var_dump($date);
//example of accessing public $date; of class DateTime;
echo $date->date;
但我得到了Undefined property: DateTime::$date in /var/www/php/test/index.php on line 7
那我应该如何解读var_dump(some class)?
【问题讨论】:
-
您运行的是什么版本的 PHP?你的操作系统是什么?我正在从命令行运行 PHP 7.3.24,
echo $date->date显示2021-02-16 22:36:17.973299 -
php 7.4.9。 5.8.0-43-generic #49-Ubuntu SMP Fri Feb 5 03:01:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux