namespace Php {
    public bool isset_value_static (zval value, string php_file, int php_line) throws Error {
        return value != null && !value.is_null ();
    }

    public zval isset_value_zval (zval value, string php_file, int php_line) throws Error {
        return zval.boolean (isset_value_static (value, php_file, php_line));
    }

    public bool empty_value_static (zval value, string php_file, int php_line) throws Error {
        if (value == null || value.is_null ())
            return true;

        switch (value.get_value_type ()) {
        case ValueType.NULL:
            return true;
        case ValueType.BOOL:
            return !value.as_bool ();
        case ValueType.INT:
            return value.as_int () == 0;
        case ValueType.DOUBLE:
            return value.as_double () == 0.0;
        case ValueType.STRING:
            string string_value = value.as_string ();
            return string_value == "" || string_value == "0";
        case ValueType.ARRAY:
            return value.count () == 0;
        case ValueType.OBJECT:
        case ValueType.RESOURCE:
            return false;
        default:
            return false;
        }
    }

    public zval empty_value_zval (zval value, string php_file, int php_line) throws Error {
        return zval.boolean (empty_value_static (value, php_file, php_line));
    }
}
