Re: Internal zvals can't be arrays

From: Date: Thu, 13 May 2004 20:42:00 +0000
Subject: Re: Internal zvals can't be arrays
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-9846@lists.php.net to get a copy of this message
I think your humor is too subtle for me. I don't understand what you mean. If I do this: PHP_METHOD(test_class,__construct); zend_class_entry *test_class_ce_ptr = NULL; static zend_function_entry test_class_functions[] = {
    PHP_ME(test_class, __construct, NULL, ZEND_ACC_PUBLIC)
    {NULL, NULL, NULL}
}; And then I put this in my MINIT function: INIT_CLASS_ENTRY(ce, "test_class", test_class_functions); test_class_ce_ptr = zend_register_internal_class(&ce TSRMLS_CC); zend_declare_property_null(test_class_ce_ptr, "test_property",
    sizeof("test_property")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
And I make test_class's constructor look like this: PHP_METHOD(test_class, __construct) {
    zval *tmp = NULL;
    ALLOC_ZVAL(tmp);
    tmp->is_ref = 0;
    tmp->refcount = 0;
    array_init(tmp);
    add_next_index_long(tmp, 100);
    zend_update_property(test_class_ce_ptr, this_ptr, "test_property", sizeof("test_property")-1, tmp TSRMLS_CC);
} Then this PHP program: $e = new test_class(); print new ReflectionClass($e); var_dump($e); Prints: Class [ <internal> class test_class ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [1] {
    Property [ <default> public $test_property ]
} - Methods [1] {
    Method [ <internal> <ctor> public method __construct ] {
    }
} } object(test_class)#1 (1) { ["test_property"]=> array(1) {
    [0]=>
    int(100)
} } So it would be handy (since all the property creation would be in one place and there wouldn't be the confusing inference from reading the code that the property is NULL) if I could create the array zval in MINIT instead of in the constructor. David Marcus Boerger wrote:
Hello David, i did most of these functions but have no idea how to create default arrays. If you find out please tell us. marcus Thursday, May 13, 2004, 9:29:02 PM, you wrote:
zend_declare_property() tells me that I can't use it to create a class property that is an array. Why is that? What is the recommended way to create an array class property?
Thanks, David


« previous php.internals (#9846) next »