Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93807 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72521 invoked from network); 5 Jun 2016 09:06:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jun 2016 09:06:24 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.213.41 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.213.41 mail-vk0-f41.google.com Received: from [209.85.213.41] ([209.85.213.41:36529] helo=mail-vk0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/63-55579-F8BE3575 for ; Sun, 05 Jun 2016 05:06:23 -0400 Received: by mail-vk0-f41.google.com with SMTP id c66so11927562vkb.3 for ; Sun, 05 Jun 2016 02:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=PnIXMOL8fvg70QGc0XxPG7sxGxWr89ReDBY0ZCu18qQ=; b=yy4xekedTs1J1sdrOayQJx+EMtPYBlEDrDGwoaoAprKtIglA2yJlhxkrI8ov8mkp8Z fmdEuTjRZcLuIEOrcQ9/JZz6jP92nHXXeZSI+NJc7BPxC0sxsuYrBHi2JVVOZdkLH0xR Y5ESljX7YhBSkzJTCBynDSIvDeoFSWXLh/CNirOPb73nHjqH2dLGN5IkYIpDAInBNits ztBxOpIQe2cE5+2b25d5Be3WstVZ+M/1jvq1VgnUiY80eQ0PxM2Ky5IVTHlbpcR98Tr7 jn17rdzSJ6mQodebxdtZTDYNZimoU0Y18l5uU+TVpfztSxRmsGzXUd5x4ZfDaGhhfqQO ceGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=PnIXMOL8fvg70QGc0XxPG7sxGxWr89ReDBY0ZCu18qQ=; b=Zg0be5umAvFwUo3PjedITswoQSj6b2poJbviFrQogSPnX9flUGG52cpcRFOfdZ1Ar0 m8Ut54Hd9oEr0O5J3n3BSr+2fAvBaDggfaxHBttf1Aedw/gWEpVif3r6DvSDfUaqw3ue UaYZnQFgvacQ0WU6Y6Oi1US6GW1U0bJMWBcChWXKJ9vZMo71RJQyxBDRDEvoqbqkdmhc JuYIuafhf89I8ixP/570ISPhFLO5PrpyizjlBXlajafFBSheJJZZuONj5ffciJxRShes EfwcKf9vw2SR0fi3p36/bPEe8HWSDngybTg8FAlpgcsSUln8stLXKednBy+K+2giHhRI bj3w== X-Gm-Message-State: ALyK8tJvoqPuYOT6n/Gu+K7MSHjDkq6gOEjd7S5bzHVRztsLuSVn0SC50pxy9iPEq5jwNcrwyrDcLjEJAwAYuQ== X-Received: by 10.159.35.40 with SMTP id 37mr5624935uae.55.1465117580802; Sun, 05 Jun 2016 02:06:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.76.200 with HTTP; Sun, 5 Jun 2016 02:06:17 -0700 (PDT) In-Reply-To: <7fe46e6a-1195-8eda-28ec-3e225fab22a3@gmail.com> References: <801c8df4-4f33-935b-5bee-ff73a0865433@gmail.com> <7fe46e6a-1195-8eda-28ec-3e225fab22a3@gmail.com> Date: Sun, 5 Jun 2016 11:06:17 +0200 Message-ID: To: Stanislav Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113bcc7ef556360534844432 Subject: Re: [PHP-DEV] can't reflection on DateTime properties? From: rasmus@mindplay.dk (Rasmus Schultz) --001a113bcc7ef556360534844432 Content-Type: text/plain; charset=UTF-8 > 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 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 > smalyshev@gmail.com > --001a113bcc7ef556360534844432--