Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88487 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69723 invoked from network); 24 Sep 2015 20:51:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2015 20:51:49 -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.223.175 as permitted sender) X-PHP-List-Original-Sender: zardozrocks@gmail.com X-Host-Fingerprint: 209.85.223.175 mail-io0-f175.google.com Received: from [209.85.223.175] ([209.85.223.175:35714] helo=mail-io0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/12-58589-56264065 for ; Thu, 24 Sep 2015 16:51:49 -0400 Received: by ioiz6 with SMTP id z6so90254841ioi.2 for ; Thu, 24 Sep 2015 13:51:46 -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 :content-type; bh=LzXRuEllkS3eLhXEBfRzsCzC2lUn+ElnSQiC4rZOBLI=; b=ja45pGJ3eccJarD1FVtgedvdlflgD0RJ6mdi2VZTZkL36V3trm95WnO11iRJdfWWe4 VYXhbnX4p3I1IbYLzkoJ3NsjACdYxZbMXyJ0Pq5r3phff6KfNFlesIe4xiaajcuc2VWf Hv9HLwOLbPWf4qtoPyhQQxg5VJ5NRC8fUdJf0ReTDBuuwtwKBXGWsA1XpTDLzHNycBz3 5K42lgOSPCHH5KBsamyDXkFMp2cA8yhP9j/ljTTB7KIGLTyN+gBGxPGTOfoYilAmhFpm Cz6vfd7GMbbskiOpQ3m36eHfaCQ+1NFQcruYYLn1m8b/6T3+LaqXcYX7ZHKUaiYnbzDS y0tA== MIME-Version: 1.0 X-Received: by 10.107.25.71 with SMTP id 68mr2742435ioz.46.1443127906547; Thu, 24 Sep 2015 13:51:46 -0700 (PDT) Received: by 10.107.31.148 with HTTP; Thu, 24 Sep 2015 13:51:46 -0700 (PDT) In-Reply-To: <20150923223556.GA45863@3006.local> References: <5601F58A.7000602@php.net> <64233ECB-7422-4D7C-A8A5-E77FC98C09E2@gmail.com> <20150923223556.GA45863@3006.local> Date: Thu, 24 Sep 2015 13:51:46 -0700 Message-ID: To: internals Content-Type: multipart/alternative; boundary=001a113ff20e3c472a05208466bb Subject: Re: [PHP-DEV] Data serialization of objects, want to iterate 'sealed' properties then dynamic ones From: zardozrocks@gmail.com (j adams) --001a113ff20e3c472a05208466bb Content-Type: text/plain; charset=UTF-8 Thank you for this, Sean! I'm making headway for php 5.5/5.6. This should come in handy when/if I get around to PHP 7. On Wed, Sep 23, 2015 at 3:35 PM, Sean DuBois wrote: > On Wed, Sep 23, 2015 at 02:16:39PM -0700, j adams wrote: > > Not my intention to be combative, but what about > http://php.net/pcntl_fork > > ? I've used that before in a robust distributed application that runs > > without any intervention for months. It's my understanding that PHP is > > thread safe, but not itself multithreaded. I believe there are some > > extensions which aren't thread safe. Also correct me if I'm wrong but > > Apache 2 should be run in it's prefork mode when using PHP. > > > > Also, any thoughts on my other questions? Sorry if I'm pressing my luck > but > > they are far more pressing for me currently: > > 1) Is there not any way to first iterate through the default properties > and > > then iterate through *only the dynamic properties* ? > > zend_object->properties appears to contain ALL properties if the object > has > > a single dynamically-assigned property. If so, please advise? If not, > it > > sounds like I must iterate through all properties and check each > property's > > key to see if it's included among the default properties. Please confirm? > > 2) Will this code ALWAYS return the properties in the same sequence? > E.g., > > if I am iterating through N objects of type MyClass, will each instance > > iterate the properties in the same order? > > 3) Will this code ALWAYS iterate over default properties (i.e., "sealed" > > properties, those explicitly defined by class definitinos) FIRST and then > > iterate any dynamically assigned properties? > > These questions are very important for my serialization algorithm. > > > > CODE: > > > > > > zobj = zend_objects_get_address(*val TSRMLS_CC); > > > > if (!zobj->properties) { > > php_printf("***No dynamic properties!\n"); > > } else { > > php_printf("***we got dynamic properties...sadly, this > will > > also iterate through default properties too\n"); > > zend_hash_internal_pointer_reset_ex(zobj->properties, > &pos); > > while (zend_hash_get_current_data_ex(zobj->properties, > > (void **) &value, &pos) == SUCCESS) { > > if (zend_hash_get_current_key_ex(zobj->properties, > > &key, &key_len, &num_index, 0, &pos) == HASH_KEY_IS_STRING) { > > if (zend_check_property_access(zobj, key, > key_len-1 > > TSRMLS_CC) == SUCCESS) { > > > > zend_unmangle_property_name(key, key_len - 1, > > &class_name, &prop_name); > > > > php_printf("dynamic property is %s, key_len > is > > %d\n", prop_name, key_len); > > } > > } > > zend_hash_move_forward_ex(zobj->properties, &pos); > > } > > } > > > > On Wed, Sep 23, 2015 at 1:33 PM, Rowan Collins > > wrote: > > > > > On 23 September 2015 20:48:33 BST, j adams > wrote: > > > >> PHP uses an object store. > > > >Am I correct in understanding that the object store is a global data > > > >structure? Wouldn't this tend to discourage any attempts at > > > >multithreading/multiprocessing within one's PHP script--unless the > > > >object > > > >store is protected by a lock... > > > > > > PHP is inherently single-threaded as far as the user is concerned. > There > > > are many things which would break if you changed that. > > > > > > The only way I know of to write multi-threaded PHP is using the > pthreads > > > extension, which comes with some rather large caveats, and uses > specific > > > objects to communicate between threads. > > > > > > Regards, > > > -- > > > Rowan Collins > > > [IMSoP] > > > > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > In PHP7 this is how you can all the default properties (defined on the > class) you will have to adjust. This is breaking public APIs, but just > to illustrate how to get you closer. > > You should then be able to determine if a property is defined on the class > or object this way. > Just build some sort of lookup table via looping over them below. > > > > PHP_FUNCTION(print_properties) > { > zval *obj_zval; > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &obj_zval) > == FAILURE) { > RETURN_FALSE; > } > > zend_class_entry *ce = Z_OBJCE_P(obj_zval); > zend_property_info *prop; > zval *val; > int prop_count = 0; > const char *class_name, *prop_name; > > ZEND_HASH_FOREACH_PTR(&ce->properties_info, prop) { > val = &ce->default_properties_table[prop_count]; > zend_unmangle_property_name(prop->name, &class_name, &prop_name); > prop_count++; > > fprintf(stdout, "%s \n", prop_name); > php_var_dump(val, 1); > } ZEND_HASH_FOREACH_END(); > > > Which will give you the following > > > > > > defaultPropertyPublic > string(17) "publicDefaultProp" > defaultPropertyPrivate > string(18) "privateDefaultProp" > defaultPropertyProtected > Int(12) > > --001a113ff20e3c472a05208466bb--