3v4l.org

run code in 500+ PHP versions simultaneously
<?php unlink('/tmp/test.phar'); $phar = new Phar('/tmp/test.phar'); $phar->startBuffering(); $phar->addFromString('1.php', 'test'); $phar->addFromString('2.php', 'test'); $phar->addFromString('inner/3.php', 'test'); $phar->stopBuffering(); $phar->rewind(); // string(24) "phar:///tmp/test.phar/" var_dump($phar->key()); // Не выведет ничего // foreach ($phar as $k => $v) { /* ... */ } // А так выведет foreach ($phar->getChildren() as $k => $v) { var_dump($k); var_dump($v); } // А так выведет даже с подкаталогами $iter = new RecursiveIteratorIterator($phar->getChildren()); foreach ($iter as $k => $v) { var_dump($k); var_dump($v); }
Output for 8.6.0
Warning: unlink(): No such file or directory in /in/YvbU3 on line 3 Fatal error: Uncaught UnexpectedValueException: creating archive "/tmp/test.phar" disabled by the php.ini setting phar.readonly in /in/YvbU3:4 Stack trace: #0 /in/YvbU3(4): Phar->__construct('/tmp/test.phar') #1 {main} thrown in /in/YvbU3 on line 4
Process exited with code 255.
Output for 8.1.28 - 8.1.34, 8.2.0 - 8.2.36, 8.3.0 - 8.3.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.13
Warning: unlink(/tmp/test.phar): No such file or directory in /in/YvbU3 on line 3 Fatal error: Uncaught UnexpectedValueException: creating archive "/tmp/test.phar" disabled by the php.ini setting phar.readonly in /in/YvbU3:4 Stack trace: #0 /in/YvbU3(4): Phar->__construct('/tmp/test.phar') #1 {main} thrown in /in/YvbU3 on line 4
Process exited with code 255.

preferences:
22.3 ms | 1168 KiB | 6 Q