Content · Programming · PHP

PHP die() Function: Usage and Examples

Learn how PHP die works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Stops script execution; die is an alias of exit.

What Is die() in PHP?

Stops script execution; die is an alias of exit.

Its syntax is:

die(string|int $status = 0): never

Parameters:

  • $status — Accepted as string|int; optional default 0.

Return type: never. An integer argument is an exit status in CLI contexts; a string is printed before termination.

Availability: Core PHP.

Example 1: Basic Usage

<?php

if (false) { die("Stopped"); } echo "Continues";

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. An integer argument is an exit status in CLI contexts; a string is printed before termination.

Example 2: A Different Input

<?php

if (false) { die(1); } echo "No exit requested";

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. An integer argument is an exit status in CLI contexts; a string is printed before termination.

Practical Example: Applying It in a Program

<?php

$requiredValue = "present"; if ($requiredValue === "") { die("Missing value"); } echo "Validated";

Result: Results and availability depend on the current PHP process, system permissions, cache, filesystem or installed locale. An integer argument is an exit status in CLI contexts; a string is printed before termination.

Important Behavior and Edge Cases

  • Key behavior: An integer argument is an exit status in CLI contexts; a string is printed before termination.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
die()Stops script execution; die is an alias of exit.
exitdie is an alias of exit; both stop the script.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: An integer argument is an exit status in CLI contexts; a string is printed before terminationAn integer argument is an exit status in CLI contexts; a string is printed before termination.

Key Takeaways

  • Stops script execution; die is an alias of exit.
  • An integer argument is an exit status in CLI contexts; a string is printed before termination.
  • Core PHP.

Summary: An integer argument is an exit status in CLI contexts; a string is printed before termination.

Share this resourceSend this page to someone who may find it useful.