PHP is_executable() Function: Usage, Parameters, Return Values, and Examples

The article explains PHP's built‑in is_executable() function, detailing its syntax, the $filename parameter, possible true/false return values, example code for checking file executability, important notes on directory checks and permission effects, and provides a brief summary.

php Courses
php Courses
php Courses
PHP is_executable() Function: Usage, Parameters, Return Values, and Examples
is_executable()

is a built‑in PHP function that checks whether a specified file can be executed. It accepts a single argument—the file path—and returns a boolean indicating executability.

Basic Usage:

bool is_executable ( string $filename )

The $filename argument can be either a relative or an absolute path to the file you want to test.

Return Values:

If the file is executable, the function returns true;

If the file is not executable or does not exist, it returns false.

Example:

// Check if a file is executable
$file = '/path/to/file.php';
if (is_executable($file)) {
    echo "File is executable";
} else {
    echo "File is not executable";
}

In this example we test the file /path/to/file.php. If it is executable, the script outputs "File is executable"; otherwise it outputs "File is not executable".

Note that is_executable() can only be used to check files, not directories. To test a directory's executability you should use the is_dir() function instead.

Also, the result of is_executable() may be influenced by the current user's file‑system permissions; if the user lacks sufficient rights, the function may return false even when the file itself has executable permissions.

Summary:

is_executable()

is a PHP function for checking whether a file has executable permission. It takes a file path as its argument and returns a boolean value, allowing developers to determine if a file can be run and handle it accordingly.

PHP Learning Recommendations:

Vue3 + Laravel8 + Uniapp Beginner to Advanced Development Tutorial

Vue3 + TP6 + API Social E‑commerce System Development Course

Swoole From Beginner to Master Recommended Course

Workerman + TP6 Real‑time Chat System Limited‑time Offer

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPFilesystemFile Permissionsis_executable
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.