|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42705 Defining sys/stat.h's constants in PHP
Submitted: 2007-09-19 05:46 UTC Modified: 2020-04-08 10:37 UTC
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: arnaud dot lb at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 5.2.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: arnaud dot lb at gmail dot com
New email:
PHP Version: OS:


 [2007-09-19 05:46 UTC] arnaud dot lb at gmail dot com
It would be very useful to have the sys/stat.h constants (S_*, e.g. 
S_ISUID for the setuid bit) defined in PHP, to be able to more 
easily use the values returned by functions such as fileperms() or 

I actually use this to define them (from stat(2) man page), but I 
guess it's not portable:
define('S_IFMT',        0170000);       //bit mask for the file type 
bit fields
define('S_IFSOCK',      0140000);       //socket
define('S_IFLNK',       0120000);       //symbolic link
define('S_IFREG',       0100000);       //regular file
define('S_IFBLK',       0060000);       //block device
define('S_IFDIR',       0040000);       //directory
define('S_IFCHR',       0020000);       //character device
define('S_IFIFO',       0010000);       //FIFO
define('S_ISUID',       0004000);       //set UID bit
define('S_ISGID',       0002000);       //set-group-ID bit (see 
define('S_ISVTX',       0001000);       //sticky bit (see below)
define('S_IRWXU',       00700); //mask for file owner permissions
define('S_IRUSR',       00400); //owner has read permission
define('S_IWUSR',       00200); //owner has write permission
define('S_IXUSR',       00100); //owner has execute permission
define('S_IRWXG',       00070); //mask for group permissions
define('S_IRGRP',       00040); //group has read permission
define('S_IWGRP',       00020); //group has write permission
define('S_IXGRP',       00010); //group has execute permission
define('S_IRWXO',       00007); //mask for permissions for others 
(not in group)
define('S_IROTH',       00004); //others have read permission
define('S_IWOTH',       00002); //others have write permission
define('S_IXOTH',       00001); //others have execute permission

This make me able to do things like ($fileperms & S_IROTH) instead 
of ($fileperms & 00004) to know if a file is world readable.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-08 10:37 UTC]
-Package: Feature/Change Request +Package: *General Issues
 [2020-04-08 10:37 UTC]
The S_IF* constants are already available in the posix extension
as of PHP 5.1.0[1].

[1] <>
 [2024-01-26 06:20 UTC] ameliabrnnr at gmail dot com
Thank you so much for the informative and interesting post. (
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 11:01:32 2024 UTC