If I use var_dump
to some class, say DateTime
:
<?php
$date = new DateTime();
var_dump($date);
I got
/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)
Which I interpret there are 3 public properties. So I try to access them:
<?php
$date = new DateTime();
var_dump($date);
//example of accessing public $date; of class DateTime;
echo $date->date;
but I got Undefined property: DateTime::$date in /var/www/php/test/index.php on line 7
So how should I interpret var_dump(some class)
?
My Answer:
Yes, `var_dump()` will show the class properties of an object when used on an instance of a class. For example, if you use `var_dump(new DateTime())`, it will display all the properties and values of the DateTime object.
Rate this post
4 of 5 based on 1409 votesComments