PHP扩展:如何返回C ++对象?

I want to build an PHP-Extension which internally calls C++-Functions returning C++-Objects. I know I have to wrap these C++-Objects in zval containers to provide them to the PHP-level.

//if returnval is long
if (color != NULL) {
    RETURN_LONG(color->GetRGBRed());
}
//if returnval is bool
if (color != NULL) {
    RETURN_BOOL(color->GetRGBRed());
}
//if returnval is double
if (color != NULL) {
    RETURN_DOUBLE(color->GetRGBRed());
}
//if returnval is string without length
if (color != NULL) {
    RETURN_STRING(color->GetRGBRed(),1; //1 or 0
}
//if returnval is string with length
if (color != NULL) {
    RETURN_STRINGL(color->GetRGBRed(),15,1);
}
//if returnval is an object
if (color != NULL) {
    zval *new_object; 
    MAKE_STD_ZVAL(new_object); 

    if(object_init(new_object) != SUCCESS)
    {
        zend_error(E_WARNING, "Objekt konnte bei Return nicht erzeugt werden.");
    }

    new_object->type=IS_OBJECT;

    zend_hash_update(
        EG(active_symbol_table),
        "new_variable_name",
        strlen("new_variable_name") + 1,
        &new_variable,
        sizeof(zval *),
        NULL
    );
}

As you see, it is easy to return a numeric value or a boolean or a string into the PHP-Space. But at the end of my code you see my attempt to return a custom C++-Object in a zval.