---
title: Do not use the same operator twice
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Do not use the same operator twice
---

# Do not use the same operator twice

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `php-best-practices/no-double-operators`

**Language:** PHP

**Severity:** Warning

**Category:** Error Prone

## Description{% #description %}

This rule advises against the use of the same operator twice in a row in PHP code. This practice can lead to confusion and errors. Using operators like `!!` or `~~` can be misleading, as their purpose might not be immediately clear to other developers reading the code.

The importance of this rule lies in the readability and maintainability of the code. Clear, readable code is crucial in any development project, as it allows other team members to understand and work on the code. It also reduces the likelihood of bugs and errors.

To adhere to this rule, avoid using the same operator twice in a row. If you are tempted to use double operators for type conversion, instead consider using explicit type conversion functions such as `boolval()` for booleans or `intval()` for integers. This will make your code more explicit and easier to understand.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```php
<?php
$myInt = 2;
$myValue1 = !!$myInt;
$myValue2 = ~~$myInt;
```

## Compliant Code Examples{% #compliant-code-examples %}

```php
<?php
$myInt = 2;
$myValue1 = boolVal($myInt);
$myValue2 = $myInt;
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 