---
title: All code should be reachable, dead code should be avoided
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > All code should be reachable, dead code should be avoided
---

# All code should be reachable, dead code should be avoided

{% 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-code-style/no-unreachable`

**Language:** PHP

**Severity:** Warning

**Category:** Error Prone

## Description{% #description %}

This rule requires that all code in a function or method must be reachable, and dead code (code that can never be executed) should be avoided. This rule is important because dead code can make the program more difficult to understand and maintain. It can also lead to confusion and bugs if other developers mistakenly believe the dead code is doing something.

Dead code often occurs when developers leave behind commented-out code or functions that are no longer called. It can also happen when a return statement or an exception is thrown before the code.

To ensure compliance with this rule, always remove code that is no longer needed. Use version control systems to keep track of changes instead of leaving old code in comments. Be mindful of the flow of your functions and methods to ensure all code is reachable. For example, if you have a `return` statement in your function, make sure it's the last operation in your function.

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

```php
<?php
function test() {
    echo "test";
    return;
    echo "testing";
}
```

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

```php
<?php
function test() {
    echo "test";
    echo "testing";
    return;
}
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 