fn php_zval_to_visit_result(val: &ext_php_rs::types::Zval) -> {{ result_type_path }} {
    if let Some(s) = val.string() {
        return match s.as_str() {
{%- for variant in unit_result_variants %}
            "{{ variant.wire_name }}" => {{ result_type_path }}::{{ variant.name }},
{%- endfor %}
{%- if single_payload_variant %}
            _ => {{ result_type_path }}::{{ single_payload_name }}(s.to_string()),
{%- else %}
            _ => {{ result_type_path }}::{{ default_variant }},
{%- endif %}
        };
    }
    if let Some(arr) = val.array() {
{%- for variant in payload_result_variants %}
        if let Some(custom_val) = arr.get("{{ variant.wire_name }}") {
            if let Some(s) = custom_val.string() {
                return {{ result_type_path }}::{{ variant.name }}(s.to_string());
            }
        }
{%- endfor %}
    }
    {{ result_type_path }}::{{ default_variant }}
}
