public static int main(string[] args) {
    PhpefRuntimeCore.init(args);
    var fp = PhpefRuntimeNativeStandard.phpfunc_fopen(
        PhpefRuntimeCore.Zval.from_string("php://temp"),
        PhpefRuntimeCore.Zval.from_string("r+")
    );
    if (!PhpefRuntimeNativeStandard.phpfunc_is_resource(fp).to_bool()) {
        stderr.printf("fopen did not return a resource\n");
        return 1;
    }
    var written = PhpefRuntimeNativeStandard.phpfunc_fwrite(fp, PhpefRuntimeCore.Zval.from_string("abc"));
    if (written.as_int() != 3) {
        stderr.printf("fwrite wrote %s bytes, expected 3\n", written.as_int().to_string());
        return 1;
    }
    if (!PhpefRuntimeNativeStandard.phpfunc_fflush(fp).to_bool()) {
        stderr.printf("fflush failed\n");
        return 1;
    }
    if (!PhpefRuntimeNativeStandard.phpfunc_fclose(fp).to_bool()) {
        stderr.printf("fclose failed\n");
        return 1;
    }
    if (PhpefRuntimeNativeStandard.phpfunc_is_resource(fp).to_bool()) {
        stderr.printf("closed handle is still reported as resource\n");
        return 1;
    }
    return 0;
}
