php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41062 is_executable only looks at basic executables
Submitted: 2007-04-12 14:07 UTC Modified: 2021-11-08 11:56 UTC
Votes:5
Avg. Score:3.8 ± 0.7
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:3 (75.0%)
From: RQuadling@php.net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 7.0.7 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: RQuadling@php.net
New email:
PHP Version: OS:

 

 [2007-04-12 14:07 UTC] RQuadling@php.net
Description:
------------
For Windows, the is_executable() function only checks the file extensions of exe, com, bat and cmd.

This is incomplete.

Within Windows, there is an environment variable called PATHEXT. This contains a list of extensions which are executable.

If you type a program whose extension is in this list and the program with that extension is in the path, then it is executed.

You can easily add .PHP to this list (see UserNote http://www.php.net/manual/en/features.commandline.php#53252). This is completely normal behaviour on windows.

Using the "FileTypes" mechanism allows any type of file to have an automatic "handler" (double click a PDF file and Acrobat loads with that file). By also adding the extension to the PATHEXT environment variable you can type just the name at the CLI and the lovely windows magic happens automagically.

The standard list of executable types within windows XP is:

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

Mine is:

PATHEXT=.COM;.EXE;.BAT;.CMD;.PHP;.PYC;.PY;

I don't deal with MS VB scripts, but I do deal with PHP and Python!

All of these are "executable" (i.e. the behaviour of an abc.php is the same as an abc.bat or an abc.exe).

Admittedly this is only on windows, but the current method should either be documented as only being of limited use on Windows (with the  4 types) or be extended to look at the Windows mechanism (just like I assume the *ix version looks at an executable bit on the permissions?).

The following is a screen grab to prove the point.

12/04/2007 15:02:28 C:\>type "d:\PHP Quickies\isexec.php"
<?php
echo $argv[0], ' is ', (is_executable($argv[0]) ? '' : 'not '), 'executable';
?>

12/04/2007 15:02:34 C:\>set path
Path=C:\Batch;C:\PHP5;D:\PHP Quickies;C:\Program Files\Windows Resource Kits\Tools;C:\Python\Lib;C:\Program Files\WinRAR;D:\Sage\UTILS;c:\program files\imagemagick;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Universal Extractor\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\Nmap;D:\Cygwin\bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.PHP;.PYC;.PY;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

12/04/2007 15:02:37 C:\>isexec
D:\PHP Quickies\isexec.php is not executable



Reproduce code:
---------------
<?php
echo is_executable($argv[0]) ? 'Executable' : 'Not executable';
?>

Expected result:
----------------
D:\PHP Quickies\isexec.php is executable

Actual result:
--------------
D:\PHP Quickies\isexec.php is not executable

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-12 02:33 UTC] pajoye@php.net
-Status: Open +Status: Assigned -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: pajoye
 [2016-06-01 04:40 UTC] Justin dot Barth at gcinema dot net
This appears to still be an issue on PHP 7.0.6 , running on windows 2012 r2 datacenter edition.
 [2016-06-02 04:54 UTC] requinix@php.net
-Status: Assigned +Status: Open -Operating System: Windows XP SP2 +Operating System: Windows -PHP Version: 5CVS-2007-04-12 (snap) +PHP Version: 7.0.7 -Assigned To: pajoye +Assigned To:
 [2016-06-02 04:54 UTC] requinix@php.net
Moving back to open - unless @pajoye wants to pick it back up.
 [2021-11-08 11:56 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Feature/Change Request +Type: Documentation Problem -Package: *General Issues +Package: Filesystem function related
 [2021-11-08 11:56 UTC] cmb@php.net
There are certainly different ways to map the is_executable() behavior
to Windows, and PHP 7.4 decided to rely on GetBinaryType()[1].  For BC
reasons, .bat and .cmd are still reported as executable additionally,
but according to the comment[2] might be removed in the future.

So this is a WONTFIX, but I'm changing to doc problem, since the
behavior is not documented at all.

[1] <https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-getbinarytypew>
[2] <https://github.com/php/php-src/blob/php-7.4.25/win32/ioutil.c#L936>
 [2021-11-08 14:05 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/8d8cd43bfcd67415f3d548b7209c5b1a63d88fd1
Log: Fix #41062: is_executable only looks at basic executables
 [2021-11-08 14:05 UTC] git@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 03 14:01:29 2024 UTC