3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function abc($file) { $perms = fileperms($file); if (($perms & 0xC000) == 0xC000) { // Socket $info = 's'; } elseif (($perms & 0xA000) == 0xA000) { // Symbolic Link $info = 'l'; } elseif (($perms & 0x8000) == 0x8000) { // Regular $info = '-'; } elseif (($perms & 0x6000) == 0x6000) { // Block special $info = 'b'; } elseif (($perms & 0x4000) == 0x4000) { // Directory $info = 'd'; } elseif (($perms & 0x2000) == 0x2000) { // Character special $info = 'c'; } elseif (($perms & 0x1000) == 0x1000) { // FIFO pipe $info = 'p'; } else { // Unknown $info = 'u'; } // Owner $info .= (($perms & 0x0100) ? 'r' : '-'); $info .= (($perms & 0x0080) ? 'w' : '-'); $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); // Group $info .= (($perms & 0x0020) ? 'r' : '-'); $info .= (($perms & 0x0010) ? 'w' : '-'); $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); // World $info .= (($perms & 0x0004) ? 'r' : '-'); $info .= (($perms & 0x0002) ? 'w' : '-'); $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); return posix_getpwuid(fileowner($file))['name'].' '.posix_getpwuid(filegroup($file))['name'].' '.$info; } echo posix_getpwuid(posix_geteuid())['name'].PHP_EOL.PHP_EOL; $d = '.'; foreach(scandir($d) as $dir) { //echo $dir.': '.substr(sprintf('%o', fileperms($dir)), -4).PHP_EOL; echo $dir.' '.abc($d.'/'.$dir).PHP_EOL; }
based on HdHZn
Output for 7.1.20, 7.2.6
nobody Warning: scandir(): open_basedir restriction in effect. File(.) is not within the allowed path(s): (/tmp:/in) in /in/BM3le on line 57 Warning: scandir(.): failed to open dir: Operation not permitted in /in/BM3le on line 57 Warning: scandir(): (errno 1): Operation not permitted in /in/BM3le on line 57 Warning: Invalid argument supplied for foreach() in /in/BM3le on line 57
Output for 5.4.0 - 7.1.10, 7.2.0
nobody Warning: scandir(.): failed to open dir: Permission denied in /in/BM3le on line 57 Warning: scandir(): (errno 13): Permission denied in /in/BM3le on line 57 Warning: Invalid argument supplied for foreach() in /in/BM3le on line 57
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/BM3le on line 53
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/BM3le on line 53
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/BM3le on line 53
Process exited with code 255.