Backend Development 4 min read

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:

<code>bool is_executable ( string $filename )</code>

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:

<code>// 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";
}
</code>

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

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

login 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.