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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to