Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93779 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1294 invoked from network); 4 Jun 2016 19:45:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jun 2016 19:45:56 -0000 Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.49 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.49 mail-lf0-f49.google.com Received: from [209.85.215.49] ([209.85.215.49:35479] helo=mail-lf0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/7A-25194-2FF23575 for ; Sat, 04 Jun 2016 15:45:55 -0400 Received: by mail-lf0-f49.google.com with SMTP id w16so73061955lfd.2 for ; Sat, 04 Jun 2016 12:45:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:subject:references:date:mime-version:content-transfer-encoding :from:message-id:in-reply-to:user-agent; bh=xFh30IMya4dOGlk0Fhg+oMGh0qWqH1YBBydybQTOLZc=; b=TS1mNld0QMjqSzfcah1Q0ekPaqO05LojwAmPii3F37A2EDnzZe71DWAte7IIDPvlKi nj2t2bXL19xz6djideAQUUcvcN1+k9VwT+fpXcdBmnA3ObMe6NqCeGFlbNmhJOaUiBpM JOCTxr8zj+y2PdovXr+SCuR5nJlHzy9y44Ue6vGbnpjz7OPW8su/+x94QgHQBSyftt6G ZsWG06RwZl5MRXbJFyewZ1Juk03oMS2XbIF8oRaSbNi8nC/TZ04ulDCCY3vyHoPFThTZ Yk28nBhXbZd3cK2JAk9uNToHfCvDB04MPCW1ccaYIxH21Iy48eHAMHGIMOD2koOv/s1f eilw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=xFh30IMya4dOGlk0Fhg+oMGh0qWqH1YBBydybQTOLZc=; b=LCrv+z8kSFyD+I12UrAO43kHWQcInHOVHCLOYnWGwEIG+6qqSaZCNryOUEsOH0JiPG ZGPUEOMugLyo7rxdtrXLFg6mYIQjcKSftsVlApeSnQEjBJ/sNmaGCW2MQyDa6Cs2W0hD EZRr47yZBt/s96uWgqlsWbQBjWUaq9KtMo/Wt1H5D1cuWnKMRgQBwu2HO5YkHapqxSAx 3o+c1NZdj3pueXlh6XVbb7wZtdbJOoBooAA7Yl37qkQrSw9Ti7Toru2reUHrpPz8x2Zt tY+1kEKw+WfN2Sx0oqhs6Wqy9hIOl2VlUJ5l3t6MKq9pDcKm360afA32Cmc6BJG8vlA9 wQhQ== X-Gm-Message-State: ALyK8tI2FxSBeLainAfYtGVGcYN3edAmTnhd6/IPdfddtI1dv8gP+u7LBDzx/q2XrISu5w== X-Received: by 10.46.5.82 with SMTP id 79mr2561159ljf.64.1465069551708; Sat, 04 Jun 2016 12:45:51 -0700 (PDT) Received: from nikita-pc (broadband-95-84-234-130.nationalcablenetworks.ru. [95.84.234.130]) by smtp.gmail.com with ESMTPSA id a10sm1083213lbr.18.2016.06.04.12.45.50 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 04 Jun 2016 12:45:50 -0700 (PDT) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "PHP internals" , "Rasmus Schultz" References: Date: Sat, 04 Jun 2016 22:45:59 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.17 (Win32) Subject: Re: [PHP-DEV] can't reflection on DateTime properties? From: inefedor@gmail.com ("Nikita Nefedov") On Sat, 04 Jun 2016 22:36:19 +0300, Rasmus Schultz wrote: > I wrote a library that can serialize/unserialize PHP object graphs to > JSON > data. > > Somebody reported it doesn't work on the DateTime class. > > Does this deliberately not work? > > $date = new DateTime(); > > var_dump($date); > > outputs: > > object(DateTime)#1 (3) { > ["date"]=> > string(19) "2016-06-04 19:30:19" > ["timezone_type"]=> > int(3) > ["timezone"]=> > string(3) "UTC" > } > > however, this... > > $reflection = new ReflectionClass('DateTime'); > > var_dump($reflection->getProperties()); > > outputs: > > array(0) { > } > > The object clearly has properties corresponding to it's internal state, > but > reflection doesn't seem to report them? > > 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? Yes, DateTime/DateTimeImmutable classes define custom `get_properties` zend_class_entry handler: http://lxr.php.net/xref/PHP_MASTER/ext/date/php_date.c#2162 Which is called whenever you `var_dump()` it or foreach over the object or call a `get_object_vars()` on it: https://3v4l.org/tNJXN But reflection on the other hand directly uses `zend_class_entry->properties_info` table which DateTime does not have: http://lxr.php.net/xref/PHP_MASTER/ext/reflection/php_reflection.c#4574