namespace PhpNative {
    public int exit_no_args_static (string php_file, int php_line) throws Error {
        return 0;
    }

    public Php.zval exit_no_args_zval (string php_file, int php_line) throws Error {
        return Php.zval.integer (exit_no_args_static (php_file, php_line));
    }

    public int exit_int_static (int status, string php_file, int php_line) throws Error {
        return status;
    }

    public Php.zval exit_int_zval (Php.zval status, string php_file, int php_line) throws Error {
        return Php.zval.integer (exit_int_static ((int) Php.zval_to_int (status), php_file, php_line));
    }

    public int exit_string_static (string message, string php_file, int php_line) throws Error {
        stdout.printf ("%s", message);
        return 0;
    }

    public Php.zval exit_string_zval (Php.zval message, string php_file, int php_line) throws Error {
        return Php.zval.integer (exit_string_static (Php.zval_to_string (message), php_file, php_line));
    }

    public Php.zval exit_zval (Php.zval status_or_message, string php_file, int php_line) throws Error {
        if (status_or_message == null || status_or_message.is_null ()) {
            return Php.zval.integer (exit_no_args_static (php_file, php_line));
        }
        if (status_or_message.get_value_type () == Php.ValueType.STRING) {
            return Php.zval.integer (exit_string_static (Php.zval_to_string (status_or_message), php_file, php_line));
        }
        return Php.zval.integer (exit_int_static ((int) Php.zval_to_int (status_or_message), php_file, php_line));
    }
}
