# Internal zvals can't be arrays

- Thread: https://externals.io/message/9844
- Original archive: https://news-web.php.net/php.internals/9844
- Started by David Sklar on 2004-05-13T19:29:02+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #9844 — David Sklar — 2004-05-13T19:29:02+00:00

URL: https://externals.io/message/9844#9844

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

---

## #9845 — Marcus Boerger — 2004-05-13T19:56:15+00:00

URL: https://externals.io/message/9844#9845 · In reply to: #9844

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




-- 
Best regards,
 Marcus                            mailto:helly@php.net

---

## #9846 — David Sklar — 2004-05-13T20:42:00+00:00

URL: https://externals.io/message/9844#9846 · In reply to: #9845

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:
> 
> 
> > […]
> 
> 
> > […]

---

## #9848 — Marcus Boerger — 2004-05-13T21:17:36+00:00

URL: https://externals.io/message/9844#9848 · In reply to: #9846

Hello David,

Thursday, May 13, 2004, 10:42:00 PM, you wrote:

> I think your humor is too subtle for me. I don't understand what you 
> mean. If I do this:

sorry i just wanted to say that if you find out a solution you should
tell it to me and that atm i don't have any idea how to do it.

[...]

Your code was absolute correct.

> 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.

Yes youle be handy. Especially when we have typehinting for arrays.

regards
marcus

---

## #9849 — David Sklar — 2004-05-13T21:28:49+00:00

URL: https://externals.io/message/9844#9849 · In reply to: #9848

> > […]
> 
> 
> sorry i just wanted to say that if you find out a solution you should
> tell it to me and that atm i don't have any idea how to do it.
> 
> [...]
> 
> Your code was absolute correct.
> 

OK, I figured that since you wrote the functions, if you couldn't figure 
it out then I was not going to be able to! :)


Thanks,
David
