> In generic case, you can't have internal state of an object, that's why it's
internal

I know that things like internal state and read-only properties are
possible for classes written in C, but those features aren't possible in
PHP code - classes that behave this way are inconsistent with classes
written in the language, and it becomes a problem in cases such as this.

> If you need to serialize data, there are serialize/unserialize handlers
for it.

That is no help at all, when you're implementing a JSON serializer.

You can see the class in question here:

https://github.com/mindplay-dk/jsonfreeze/blob/master/mindplay/jsonfreeze/JsonSerializer.php

Because DateTime does not behave like other classes, the only work-around
is to explicitly handle DateTime with an if/instanceof-statement and handle
that particular class explicitly.

There are plenty of work-arounds - the point is that this class doesn't
behave consistently with any other PHP class.


On Sat, Jun 4, 2016 at 10:23 PM, Stanislav Malyshev <smalys...@gmail.com>
wrote:

> Hi!
>
> > The object clearly has properties corresponding to it's internal state,
> but
> > reflection doesn't seem to report them?
>
> Reflection reports defined properties, but classes can have dynamic
> properties that are not pre-defined. var_dump also has a separate
> handler, so the object can present different information to var_dump.
>
> > 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?
>
> In generic case, you can't have internal state of an object, that's why
> it's internal. If you need to serialize data, there are
> serialize/unserialize handlers for it.
>
> --
> Stas Malyshev
> smalys...@gmail.com
>

Reply via email to