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 <rowan.coll...@gmail.com>
> wrote:
>
> > On 23 September 2015 20:48:33 BST, j adams <zardozro...@gmail.com> 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.


<code>
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();
</code>

Which will give you the following

<script>

<?php

class SeanTest {
  public $defaultPropertyPublic = 'publicDefaultProp';
  private $defaultPropertyPrivate = 'privateDefaultProp';
  protected $defaultPropertyProtected = 12;

}

$foo = new SeanTest();

$foo->runtimeProperty = 3;

print_properties($foo);

</script>


<output>
defaultPropertyPublic
string(17) "publicDefaultProp"
defaultPropertyPrivate
string(18) "privateDefaultProp"
defaultPropertyProtected
Int(12)
</output>

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to