Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88422 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89194 invoked from network); 22 Sep 2015 19:53:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Sep 2015 19:53:14 -0000 Authentication-Results: pb1.pair.com header.from=zardozrocks@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zardozrocks@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.181 as permitted sender) X-PHP-List-Original-Sender: zardozrocks@gmail.com X-Host-Fingerprint: 209.85.213.181 mail-ig0-f181.google.com Received: from [209.85.213.181] ([209.85.213.181:38524] helo=mail-ig0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/20-22010-6A1B1065 for ; Tue, 22 Sep 2015 15:53:11 -0400 Received: by igxx6 with SMTP id x6so16281417igx.1 for ; Tue, 22 Sep 2015 12:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=gKr/qUtNy8VKuwyF8/MR8cDUCgOjdZ7FWbly2gxRXYc=; b=OZLdPHR46vkT3T9Sf/1RSwrrO+wKqdosPY5yUe8tdKJ+rhFKGQCC/jI/fQCGdfkxk/ bGqIS0MqSRurFvrXrTKyrfvoGfCDGmUZokltc/hQFzWBUSmbgrMyBYkeZpiSKFtZnu3E d2x1pKDx1doFRVL6353NVEnl7KRoioQAJL8fgVHPQ6kvfgbofcDTeb5Y27wY5A86GnBb neDyveDia6w1mZeCGGA5xHrzSEejKE+Kr+Q879RAJ6L/VUHvpgBLvbgU6KpTH6IkCIx3 2+7z9+16BolI51MGMtLcrNd2XLoW8kbQZvi4vvX8VR41wrh4L0AIYIvKHjDdPE3ZQrBV i9sg== MIME-Version: 1.0 X-Received: by 10.50.2.68 with SMTP id 4mr18250954igs.7.1442951587161; Tue, 22 Sep 2015 12:53:07 -0700 (PDT) Received: by 10.107.31.148 with HTTP; Tue, 22 Sep 2015 12:53:07 -0700 (PDT) In-Reply-To: <20150922193233.GA6474@3006.local> References: <20150922193233.GA6474@3006.local> Date: Tue, 22 Sep 2015 12:53:07 -0700 Message-ID: To: Sean DuBois Cc: internals Content-Type: multipart/alternative; boundary=089e01183810c7ef9105205b5839 Subject: Re: [PHP-DEV] Data serialization of objects, want to iterate 'sealed' properties then dynamic ones From: zardozrocks@gmail.com (j adams) --089e01183810c7ef9105205b5839 Content-Type: text/plain; charset=UTF-8 Thank you, Sean. Still looking for a couple of answers... > 1) 'Default Properties' or properties stored on the class (not object) can be found on the zend_class_entry[0], they are just accessed by offset [1] > This isn't a stable/public API, but good for a cool hack! I'm afraid I don't follow. Could you elaborate? I've seen one way to get 'default properties' from a zend_class_entry object: zendClassEntry->default_properties; This gets us a list of default properties. I've also seen zendClassEntry->properties_info; Which, if I'm not mistaken, involves more elaborate parsing logic but also tells you whether properties are accessible. Seems like numerous ways to skin a cat. What is the orthodox approach here? Also, what do you suggest to distinguish 'sealed' (i.e., default) properties from dynamic ones? Is there some counterpart to default_properties that returns non_default_properties -- i.e., just the dynamic ones? Or should I just get all of the object's properties and check each key to see if it's one of the default_properties by searching a HashTable of these default properties? > 3) Never used this, but it seems to be to confirm that a mangled prop name matches a zend_property_info * Not sure I follow. We create a separate zobj of type zend_object using the function: zobj = zend_objects_get_address(obj TSRMLS_CC); And then use zobj to check access: if (zend_check_property_access(zobj, key, key_len-1 TSRMLS_CC) == SUCCESS) { I find it odd that our native zval type would not encompass member accessibility. I'm wondering if zend_object might be some kind of historical add-on concept to expand very old PHP functionality or if there's some reason for this distinct object type. On Tue, Sep 22, 2015 at 12:32 PM, Sean DuBois wrote: > On Tue, Sep 22, 2015 at 11:16:46AM -0700, j adams wrote: > > I'm working on a data serialization routine wherein I must iterate > through > > an object's properties while distinguishing between "sealed" properties > > (i.e., those specified by class definitions) and "dynamic" properties" > > (i.e., those assigned ad-hoc to some object that are not party of any > class > > definition). > > > > I found the source of the php function get_object_vars(): > > http://lxr.php.net/xref/PHP_5_6/Zend/zend_builtin_functions.c#985 > > However, I am still pretty confused. PHP source is *full* of macros and > has > > basically no comments. Hoping for some tips to keep me on the right > track. > > I'm pretty sure I can get something kludgy working, but I want my code to > > be orthodox and work well. > > > > QUESTIONS > > 1) Sadly, this approach is unable to distinguish "sealed" properties from > > dynamic ones. If anyone can refer me to some source (or outline a general > > approach) which can first iterate sealed properties and then iterate only > > dynamic ones, that would be extremely helpful. > > > > 2) What does zend_objects_get_address do? This reference looks very > > different than the usual macro, e.g. Z_OBJ_HT_P > > > > 3) Am I correct in understanding that zend_check_property_access simply > > checks if the property in question is availabe in the scope in which this > > function call gets executed? Is this the canonical/orthodox way to make > > this check? > > > > 4) What does zend_unmangle_property_name do? Why is this function changed > > to zend_unmangle_property_name_ex in 5.5 and later? > > > > 5) Why do we call Z_ADDREF_PP(value) here? Is this reference counting to > > prevent garbage collection? > > > > 6) An IS_INTERNED check is added in php 5.6 and yet the macro for > > IS_INTERNED is zero. What's that all about? > > > > 7) The code looks quite different between the different versions: > > 5.3 - http://lxr.php.net/xref/PHP_5_3/Zend/zend_builtin_functions.c#950 > > 5.5 - http://lxr.php.net/xref/PHP_5_5/Zend/zend_builtin_functions.c#982 > > 5.6 - http://lxr.php.net/xref/PHP_5_6/Zend/zend_builtin_functions.c#985 > > From what I can tell there is at least one difference between 5.3 and 5.6 > > -- zend_unmangle_property_name_ex does not exist before 5.5. Can anyone > > recommend how to make code that'll work in 5.3-5.6? Also, with 7 coming > out > > I'd like it work there too. > > > > Any answers or assistance would be greatly appreciated. > Hey, > > 1) 'Default Properties' or properties stored on the class (not object) > can be found on the zend_class_entry[0], they are just accessed by offset > [1] > > This isn't a stable/public API, but good for a cool hack! > > 3) Never used this, but it seems to be to confirm that a mangled prop name > matches a > zend_property_info * > > 4) [2] Is some good reading on property name mangling > > 5) [3] Pretty much! Refcount is just to keep track of when a zval can be > destroyed > > Hopefully the more educated members of the list can follow up and fix my > errors, but for now that > will at least get you going/able to dive deeper. > > > [0] http://lxr.php.net/xref/PHP_5_6/Zend/zend.h#488 > [1] http://lxr.php.net/xref/PHP_5_6/ext/reflection/php_reflection.c#3410 > [2] > http://www.phpinternalsbook.com/classes_objects/internal_structures_and_implementation.html > [3] http://www.phpinternalsbook.com/zvals/memory_management.html > --089e01183810c7ef9105205b5839--