Example #1
0
static PHP_METHOD(Hello, addProperties) {
    zval *obj;
    obj = getThis();

    /*add zval property*/
    zval *arr;
    MAKE_STD_ZVAL(arr);
    array_init(arr);
    add_assoc_string(arr, "e", "hello", 1);
    add_index_string(arr, 1, "hello1111", 1);
    add_property_zval_ex(obj, "persons", strlen("persons")+1, arr TSRMLS_CC);
    Z_DELREF_P(arr);


    /*add double property*/
    add_property_double(obj, "d", 10.5);

    /*add bool property*/
    add_property_bool(obj, "b", 1);

    /*add string property*/
    char *str = "hello str";
    add_property_string(obj, "str", str, 1);
    
    /*add long property*/
    add_property_long(obj, "l", 12);
}
Example #2
0
static void json_path_append_zval(json_path_object *intern, json_path *path, zval *zv)
{
    if (path->collection_stack.len > 0) {
        json_path_stack_elem *stack_elem = simple_vector_get_last(
            &intern->path_stack, json_path_stack_elem);
        zval *outer_zv = *simple_vector_get_last(
            &path->collection_stack, zval *);

        zval_add_ref(&zv);

        if (stack_elem->type == TYPE_ARRAY) {
            add_next_index_zval(outer_zv, zv);
        } else {
            if (intern->objects_as_arrays) {
                add_assoc_zval_ex(outer_zv, stack_elem->key,
                    stack_elem->key_len+1, zv);
            } else {
                add_property_zval_ex(outer_zv, 
                    (stack_elem->key_len ? stack_elem->key : "_empty_"),
                    (stack_elem->key_len ? stack_elem->key_len+1 : sizeof("_empty_")),
                    zv);
                Z_DELREF_P(zv);
            }
        }
    }
Example #3
0
PHP_METHOD(basic_container, __construct)
{

    zval *config_files;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &config_files) == FAILURE) {
        return ;
    }

    zval *_classes;
    MAKE_STD_ZVAL(_classes);
    array_init(_classes);
    add_property_zval_ex(getThis(), ZEND_STRL("_classes"), _classes TSRMLS_CC);

    zval *_lazy_classes;
    MAKE_STD_ZVAL(_lazy_classes);
    array_init(_lazy_classes);
    add_property_zval_ex(getThis(), ZEND_STRL("_lazy_classes"), _lazy_classes TSRMLS_CC);

}
Example #4
0
	void KPHPObject::Set(const char *name, SharedValue value)
	{
		// zend_update_property will call the write_property handler, but will
		// error out if the handler is NULL. add_property_zval_ex will try to
		// call the write_property handler without checking if it's NULL. Both
		// of these functions are exposed in the API with *NO* documentation.
		// and terribly misleading names.

		// That said, we'll do our own check for the write_property handler and
		// throw our own exception if it fails. This way we can handle the NULL
		// case, but not have to deal with zend_error handling.

		if (Z_OBJ_HANDLER_P(object, write_property))
		{
			zval* zvalue = PHPUtils::ToPHPValue(value);
			TSRMLS_FETCH();
			add_property_zval_ex(object, name, strlen(name)+1, zvalue TSRMLS_CC);
		}
		else
		{
			throw ValueException::FromFormat("Could not set property '%s': "
				"missing write_property handler", name);
		}
	}