> Of course they are possible. See __get/__set

Not the same thing at all - PDOStatement::$queryString is a read-only
property, which cannot be overridden, not even with __get() as you would be
able to for regular __get() in a regular PHP class.

It's also impossible to write a PHP class with "internal state" - state
that I can't find at run-time with reflection. That's what makes the
language reflective. Internal state in this sense is something foreign to
PHP as well, the only exception being things like resources, but those
aren't really types in the first place, but handles to file-system objects,
representing state outside of the program.

We're talking about a simple object representing an integer timestamp and a
timezone ID. There is no logical reason those should be hidden - it's just
an implementation detail showing up as an artifact.

> It does. It's just PHP classes can behave in more ways than you think :)
> And to some of the ways there's no good access from PHP space.

You're describing implementation details - these are features of C, not
features of the PHP language, they happen to leak into the into the PHP
language where they present themselves as inconsistencies.

The fact is that DateTime does not behave like a PHP class in terms of
reflection.

PHP being a reflective language, that's a language inconsistency. What else
would you call it?


On Sun, Jun 5, 2016 at 12:59 AM, Stanislav Malyshev <smalys...@gmail.com>
wrote:

> Hi!
>
> > 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
>
> Of course they are possible. See __get/__set. But yes, internal classes
> work a bit differently, which is no wonder since they can use internal
> handlers which are not available to PHP code.
>
> > That is no help at all, when you're implementing a JSON serializer.
>
> Right, DateTime does not implement Serializable. Probably might be a
> good idea to make it do that.
>
> Otherwise - though in general it is not a very good idea to serialize
> objects which didn't declare they are serializeable, especially internal
> ones. But if one feels adventurous the handler to use would be
> get_properties, and converting to array uses this handler, so you could
> do that. It's the same handler serializers use to get properties, unless
> Serializable is implemented or __sleep is defined.
>
> > 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.
>
> It does. It's just PHP classes can behave in more ways than you think :)
> And to some of the ways there's no good access from PHP space.
> --
> Stas Malyshev
> smalys...@gmail.com
>

Reply via email to