Php Extension: adding element to array property
| From: | Franky Braem | Date: | Wed, 11 Feb 2004 21:38:35 +0000 |
| Subject: | Php Extension: adding element to array property | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-423@lists.php.net to get a copy of this message | ||
Hi,
I'm trying to write a php extension. I've created a class that contains a property which is an array.
The class has one method to add elements to this property:
Eg. $pt = new PhpTemplate();
$pt->assign('name', 'Franky');
The above example must add a 'name' element to the tpl_vars property of the class PhpTemplate. When I debug
the
application in PHP I see that the element is added, but that no value is set. I use the following C++ code
for
the assign function:
PHP_FUNCTION(phptemplate_assign)
{
if (ZEND_NUM_ARGS() != 2)
{
WRONG_PARAM_COUNT;} char *str; int len; zval *var; if ( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/", &str, &len, &var) == FAILURE) {
php_error(E_ERROR, "Invalid arguments for assign");
RETURN_FALSE;
}
zval **vars;
if( zend_hash_find(HASH_OF(this_ptr),
"tpl_vars", 9, (void **)&vars) == SUCCESS){
convert_to_array(*vars);
add_assoc_zval(*vars, (char *) str, var);
RETURN_TRUE;
}
else
{
php_error(E_ERROR, "Invalid phpTemplate object");
RETURN_FALSE;
}
}
Does anybody know what I'm doing wrong?
Franky.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/