On Sat, 04 Jun 2016 22:36:19 +0300, Rasmus Schultz <ras...@mindplay.dk>
wrote:
I wrote a library that can serialize/unserialize PHP object graphs to
JSON
data.
Somebody reported it doesn't work on the DateTime class.
Does this deliberately not work?
$date = new DateTime();
var_dump($date);
outputs:
object(DateTime)#1 (3) {
["date"]=>
string(19) "2016-06-04 19:30:19"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
however, this...
$reflection = new ReflectionClass('DateTime');
var_dump($reflection->getProperties());
outputs:
array(0) {
}
The object clearly has properties corresponding to it's internal state,
but
reflection doesn't seem to report them?
Also, what comes out of var_dump() appears to be something intended for
human consumption? I'm guessing that's not the actual internal state of
the
object - most likely the internal state consists of the "timezone_type"
and
an integer timestamp?
Yes, DateTime/DateTimeImmutable classes define custom `get_properties`
zend_class_entry handler:
http://lxr.php.net/xref/PHP_MASTER/ext/date/php_date.c#2162
Which is called whenever you `var_dump()` it or foreach over the object or
call a `get_object_vars()` on it: https://3v4l.org/tNJXN
But reflection on the other hand directly uses
`zend_class_entry->properties_info` table which DateTime does not have:
http://lxr.php.net/xref/PHP_MASTER/ext/reflection/php_reflection.c#4574
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php