Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88426 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9415 invoked from network); 23 Sep 2015 00:42:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Sep 2015 00:42:59 -0000 Authentication-Results: pb1.pair.com header.from=francois@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=francois@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 212.27.42.6 as permitted sender) X-PHP-List-Original-Sender: francois@php.net X-Host-Fingerprint: 212.27.42.6 smtp6-g21.free.fr Received: from [212.27.42.6] ([212.27.42.6:9753] helo=smtp6-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F8/62-22010-F85F1065 for ; Tue, 22 Sep 2015 20:42:56 -0400 Received: from [127.0.0.1] (unknown [82.232.41.54]) (Authenticated sender: flaupretre@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id 6570582243; Wed, 23 Sep 2015 02:34:58 +0200 (CEST) To: j adams , internals References: Message-ID: <5601F58A.7000602@php.net> Date: Wed, 23 Sep 2015 02:42:50 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 150922-1, 22/09/2015), Outbound message X-Antivirus-Status: Clean Subject: Re: [PHP-DEV] Data serialization of objects, want to iterate 'sealed' properties then dynamic ones From: francois@php.net (=?UTF-8?Q?Fran=c3=a7ois_Laupretre?=) Hi, Hope this can help. Le 22/09/2015 20:16, j adams a écrit : > 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. Welcome to the jungle > 2) What does zend_objects_get_address do? This reference looks very > different than the usual macro, e.g. Z_OBJ_HT_P PHP uses an object store. This allows handling objects by reference. Every object instance is defined by a numeric handle (an offset in the object store). Object zvals contain the object handle. The object address is obtained through the object store. Look http://lxr.php.net/xref/PHP_5_6/Zend/zend_objects_API.c#274 Z_OBJ_HT() is used to call an object's handlers. This information is also present in the zend_object but, for a better performance AFAIK, also made available in the zval struct. > 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? Yes > > 4) What does zend_unmangle_property_name do? Why is this function changed > to zend_unmangle_property_name_ex in 5.5 and later? Properties are stored using 'mangled' names. The format of a mangled name is '', where is a null byte. Class name and property name are 'decoded' by zend_unmangle_property_name(). Look http://lxr.php.net/xref/PHP_5_6/Zend/zend_compile.c#5373 > 5) Why do we call Z_ADDREF_PP(value) here? Is this reference counting to > prevent garbage collection? This is reference counting. Incremented because a reference to the 'value' zval is added to the result array. > 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. Making code working with 5.3-5.6 is quite easy with a pair of ifdef. Unfortunately, writing code to compile on PHP 5 & 7 is complex. It seems most people porting extensions to PHP 7 finally duplicated most, if not all of their code. Regards François