Re: can't reflection on DateTime properties?

From: Date: Sat, 04 Jun 2016 20:21:53 +0000
Subject: Re: can't reflection on DateTime properties?
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-93780@lists.php.net to get a copy of this message
On Sat, Jun 4, 2016 at 9:42 PM, Jordi Boggiano <j.boggiano@seld.be> wrote: > On 04/06/2016 20:36, Rasmus Schultz 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? >> > > I can't tell you why it acts like this, but in case you are looking for a > workaround: https://3v4l.org/V5cfl > > Cheers > > -- > Jordi Boggiano > @seldaek - http://seld.be > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > The simplified workaround is to cast a DateTime object to an array: https://3v4l.org/DESiq

« previous php.internals (#93780) next »