3v4l.org

run code in 200+ PHP versions simultaneously
<?php var_dump(decoct(umask(22))); $srcDir = '/tmp/files'; mkdir($srcDir); foreach([1, 2] as $i){ $file = tempnam($srcDir, 'test'); printf("File$i - %o\n", stat($file)['mode']); } $phar = new \PharData('/tmp/test.tar', null, null, \Phar::TAR); $phar->buildFromIterator(new \RecursiveDirectoryIterator($srcDir, \FilesystemIterator::SKIP_DOTS), $srcDir); $phar->addFile($file, 'added-with-add-file'); $phar->extractTo('/tmp/pharFiles'); foreach(new \RecursiveDirectoryIterator('/tmp/pharFiles', \FilesystemIterator::SKIP_DOTS) as $iFile) { printf('From ' . ($iFile->getFilename() === 'added-with-add-file' ? 'addFile':'Iterator'). " - %o\n", $iFile->getPerms()); }
based on fbqTl
Output for 7.2.28, 7.3.15 - 7.3.18, 7.4.3 - 7.4.6
string(2) "22" File1 - 100600 File2 - 100600 From addFile - 100600 From Iterator - 100600 From Iterator - 100600
Output for 5.6.39 - 5.6.40, 7.0.33, 7.1.25 - 7.1.33, 7.2.13 - 7.2.27, 7.3.0 - 7.3.14, 7.4.0 - 7.4.2
string(2) "22" File1 - 100600 File2 - 100600 From addFile - 100600 From Iterator - 100666 From Iterator - 100666
Output for 5.4.0 - 5.4.4, 5.4.6 - 5.4.21, 5.4.23 - 5.6.12, 5.6.14, 5.6.16 - 5.6.38, 7.0.0 - 7.0.32, 7.1.0 - 7.1.4, 7.1.6 - 7.1.15, 7.1.17 - 7.1.24, 7.2.0 - 7.2.12
string(2) "22" File1 - 100600 File2 - 100600 From addFile - 100666 From Iterator - 100666 From Iterator - 100666
Output for 7.1.16
string(2) "22" File1 - 100600 File2 - 100600 Warning: PharData::extractTo(/tmp/pharFiles/added-with-add-file): failed to open stream: No such file or directory in /in/qCPRH on line 13 Fatal error: Uncaught PharException: Extraction from phar "/tmp/test.tar" failed: Cannot extract "added-with-add-file", could not open for writing "/tmp/pharFiles/added-with-add-file" in /in/qCPRH:13 Stack trace: #0 /in/qCPRH(13): PharData->extractTo('/tmp/pharFiles') #1 {main} thrown in /in/qCPRH on line 13
Process exited with code 255.
Output for 7.1.5
string(2) "22" Warning: stat(): stat failed for /tmp/files/testRFUyE2 in /in/qCPRH on line 7 File1 - 0 Notice: tempnam(): file created in the system's temporary directory in /in/qCPRH on line 6 File2 - 100600 Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/tmp/files): failed to open dir: No such file or directory in /in/qCPRH:10 Stack trace: #0 /in/qCPRH(10): RecursiveDirectoryIterator->__construct('/tmp/files', 4096) #1 {main} thrown in /in/qCPRH on line 10
Process exited with code 255.
Output for 5.4.5, 5.4.22, 5.6.13, 5.6.15
string(2) "22" File1 - 100600 File2 - 100600 Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/tmp/files): failed to open dir: No such file or directory' in /in/qCPRH:10 Stack trace: #0 /in/qCPRH(10): RecursiveDirectoryIterator->__construct('/tmp/files', 4096) #1 {main} thrown in /in/qCPRH on line 10
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/qCPRH on line 5
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/qCPRH on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/qCPRH on line 5
Process exited with code 255.