# Newbie help

- Thread: https://externals.io/message/13002
- Original archive: https://news-web.php.net/php.internals/13002
- Started by Robert Silva on 2004-09-27T01:28:16+00:00
- Messages: 4
- 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

---

## #13002 — Robert Silva — 2004-09-27T01:28:16+00:00

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

Trying to register a constant value for a class and it keeps crashing. 
Learning C as I go, so I would appreciate some insight. I can figure out
that my *property value is lost during zend_hash_add() but my knowledge
stops there as to why. Tried passing property as property and &property.

ZEND_METHOD(zboolean, __construct)
{
	zval *object = getThis();
      zval *property
  
    	ALLOC_ZVAL(property);
    	INIT_PZVAL(property);
	ZVAL_STRING(property, "true", 1);
	zend_hash_add(&(Z_OBJCE_P(object))->constants_table, "TrueString",
sizeof("TrueString")+1, property, sizeof(zval *));
}


Thanks

Bob

---

## #13013 — Andrei Zmievski — 2004-09-27T16:14:30+00:00

URL: https://externals.io/message/13002#13013 · In reply to: #13002

> Trying to register a constant value for a class and it keeps crashing. 
> Learning C as I go, so I would appreciate some insight. I can figure out
> that my *property value is lost during zend_hash_add() but my knowledge
> stops there as to why. Tried passing property as property and &property.
> 
> ZEND_METHOD(zboolean, __construct)
> {
> 	zval *object = getThis();
>       zval *property
>   
>     	ALLOC_ZVAL(property);
>     	INIT_PZVAL(property);
> 	ZVAL_STRING(property, "true", 1);
> 	zend_hash_add(&(Z_OBJCE_P(object))->constants_table, "TrueString",
> sizeof("TrueString")+1, property, sizeof(zval *));
> }

zend_hash_add(&(Z_OBJECE_P(object))->constants_table, "TrueString",
              sizeof("TrueString"), &property, sizeof(zval *), NULL);

should work.

- Andrei

---

## #13015 — George Schlossnagle — 2004-09-27T16:42:54+00:00

URL: https://externals.io/message/13002#13015 · In reply to: #13013

> 
> > […]
>
> zend_hash_add(&(Z_OBJECE_P(object))->constants_table, "TrueString",
>               sizeof("TrueString"), &property, sizeof(zval *), NULL);

The key being that sizeof("Foo") == strlen("Foo") + 1

George

---

## #13031 — Alan Knowles — 2004-09-27T23:31:27+00:00

URL: https://externals.io/message/13002#13031 · In reply to: #13015

Is there a reason there is no macro for this? (took me a while to figure 
it out as well)

And should it be done in PHP_MINIT_FUNCTION(), rather than __construct

Regards
Alan


George Schlossnagle wrote:

>
> 
>
> > […]
>
>
> The key being that sizeof("Foo") == strlen("Foo") + 1
>
> George
