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.
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
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.