Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93792 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26039 invoked from network); 4 Jun 2016 22:59:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2016 22:59:34 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.42 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.218.42 mail-oi0-f42.google.com Received: from [209.85.218.42] ([209.85.218.42:36209] helo=mail-oi0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 01/3F-25194-65D53575 for ; Sat, 04 Jun 2016 18:59:34 -0400 Received: by mail-oi0-f42.google.com with SMTP id j1so177285395oih.3 for ; Sat, 04 Jun 2016 15:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=ipCwBR5EyanA6hJkE+T1VGEtY7hGy8ePhkfdeWFD+og=; b=cyFa+I7Zlf163vEXmJSAzQSMS3K6WRAOyEVYrmyvttmzjE4WuwC8KiVCYSFBkDU3rK R+4CebBrL87lZbu4t2hcUYQx6ZCm1lyef2fng7pI6mEImc8OrK4DZSUaalBzyT+ggQiS yldYHJaw5hDf817atCVddTkVtSN4JY/43Bgxaxh7lzvYJ968Da8duAwJyg0EDwrTBAsi I6VLOJilhXNsZugCt58P6cOJO0wxFUWCIECZvfUFde4bwH8aQcYo/0qpdmsBnOuMAhjU crBjry6q26smM8ElDVJQJfHhQez6CoJg6zaw09r3HoPhuAwF4TpPsCH0De/W/H7qfyDS OQ1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=ipCwBR5EyanA6hJkE+T1VGEtY7hGy8ePhkfdeWFD+og=; b=LFwsCSkMb01j+uujpAHCQ4vlgtnwvTJPeAdq6z18bs4FvAhVkkZG+Th7v/Qz/lPWdp 8Fk35DhwsrDsVFESKu+BoRzktiS+Omtt+tsdqVSfLl7mDOOAoN5XIxK2Tbi3reLk+i32 13RzapYyoQTcksm/+LwuJctD9XySEyPpL630eJ3HiwDkukfwhw6ervBhbfxbRc/qAmFc 1j0Uz4a2UvoGA8zLRq1qvLyVEtg0kvpazTzi2Ouqws00njZnHWzuv3wtOR3OrKaSJkZo RDii8P8qZxAqPpBnlmvpDZMgCySn2ccpmrAO6UJmVl8rwGTfICK+d5x7aiSZm5i2pAzL 9xBw== X-Gm-Message-State: ALyK8tJ5cAhfkJtBtIToWOSwVWYV4rnZzGh8JPa0N7gaxNyC/9OwizEfWpkCYHSALZ9atQ== X-Received: by 10.202.225.8 with SMTP id y8mr5610316oig.192.1465081171844; Sat, 04 Jun 2016 15:59:31 -0700 (PDT) Received: from stas-air.attlocal.net (76-220-46-95.lightspeed.sntcca.sbcglobal.net. [76.220.46.95]) by smtp.gmail.com with ESMTPSA id u35sm6791688otb.38.2016.06.04.15.59.30 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 04 Jun 2016 15:59:30 -0700 (PDT) To: Rasmus Schultz References: <801c8df4-4f33-935b-5bee-ff73a0865433@gmail.com> Cc: PHP internals Message-ID: <7fe46e6a-1195-8eda-28ec-3e225fab22a3@gmail.com> Date: Sat, 4 Jun 2016 15:59:31 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] can't reflection on DateTime properties? From: smalyshev@gmail.com (Stanislav Malyshev) 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