3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Bug { class Directory extends \RecursiveDirectoryIterator { protected $_splFileInfoClass = null; protected $_relativePath = null; public function __construct ( $path, $flags = null, $splFileInfoClass = null ) { if(null === $flags) parent::__construct($path); else parent::__construct($path, $flags); $this->setSplFileInfoClass($splFileInfoClass); $this->setRelativePath($path); return; } public function current ( ) { $out = parent::current(); if( null !== $this->_splFileInfoClass && $out instanceof \SplFileInfo) { $out->setInfoClass($this->_splFileInfoClass); $out = $out->getFileInfo(); if($out instanceof SplFileInfo) $out->setRelativePath($this->getRelativePath()); } return $out; } public function getChildren ( ) { $out = parent::getChildren(); $out->setRelativePath($this->getRelativePath()); if($out instanceof \RecursiveDirectoryIterator) $out->setSplFileInfoClass($this->_splFileInfoClass); return $out; } public function setSplFileInfoClass ( $splFileInfoClass ) { $this->_splFileInfoClass = $splFileInfoClass; return; } public function setRelativePath ( $path ) { $this->_relativePath = $path; return; } public function getRelativePath ( ) { return $this->_relativePath; } } class SplFileInfo extends \SplFileInfo { protected $_relativePath = null; public function __construct ( $filename, $relativePath = null ) { parent::__construct($filename); $this->_relativePath = $relativePath; return; } public function setRelativePath ( $relativePath ) { $old = $this->_relativePath; $this->_relativePath = $relativePath; return $old; } public function getRelativePath ( ) { return $this->_relativePath; } public function getRelativePathname ( ) { if(null === $relative = $this->getRelativePath()) return $this->getPathname(); return substr($this->getPathname(), strlen($relative)); } } } namespace { $finder = new Bug\Directory('/in'); $finder->setSplFileInfoClass('Bug\SplFileInfo'); foreach(new \RecursiveIteratorIterator($finder) as $entry) var_dump($entry->getRelativePathname()); }
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.4, 8.2.6 - 8.2.10, 8.2.12 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of Bug\Directory::getChildren() should either be compatible with RecursiveDirectoryIterator::getChildren(): RecursiveDirectoryIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 39 Deprecated: Return type of Bug\Directory::current() should either be compatible with FilesystemIterator::current(): SplFileInfo|FilesystemIterator|string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 22 string(2) "/." string(3) "/.." string(6) "/bMrh7"
Output for 8.3.5
Deprecated: Return type of Bug\Directory::getChildren() should either be compatible with RecursiveDirectoryIterator::getChildren(): RecursiveDirectoryIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 39 Deprecated: Return type of Bug\Directory::current() should either be compatible with FilesystemIterator::current(): SplFileInfo|FilesystemIterator|string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 22 string(2) "/." string(3) "/.." string(6) "/bMrh7" string(6) "/bJkDF"
Output for 8.2.11
Deprecated: Return type of Bug\Directory::getChildren() should either be compatible with RecursiveDirectoryIterator::getChildren(): RecursiveDirectoryIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 39 Deprecated: Return type of Bug\Directory::current() should either be compatible with FilesystemIterator::current(): SplFileInfo|FilesystemIterator|string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 22 string(2) "/." string(3) "/.." string(6) "/bMrh7" string(6) "/kWVfN" string(6) "/rcW8e"
Output for 8.2.5
Deprecated: Return type of Bug\Directory::getChildren() should either be compatible with RecursiveDirectoryIterator::getChildren(): RecursiveDirectoryIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 39 Deprecated: Return type of Bug\Directory::current() should either be compatible with FilesystemIterator::current(): SplFileInfo|FilesystemIterator|string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 22 string(2) "/." string(3) "/.." string(6) "/bMrh7" string(6) "/o4vDc"
Output for 8.1.28
Deprecated: Return type of Bug\Directory::getChildren() should either be compatible with RecursiveDirectoryIterator::getChildren(): RecursiveDirectoryIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 39 Deprecated: Return type of Bug\Directory::current() should either be compatible with FilesystemIterator::current(): SplFileInfo|FilesystemIterator|string, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/bMrh7 on line 22 string(2) "/." string(3) "/.." string(6) "/SJOoL" string(6) "/MT3oU" string(6) "/bMrh7"
Output for 7.2.29 - 7.2.33, 7.3.16 - 7.3.29, 7.3.33, 7.4.3, 7.4.6 - 7.4.16, 7.4.21, 7.4.26 - 7.4.33, 8.0.0, 8.0.2 - 8.0.3, 8.0.7 - 8.0.9, 8.0.14 - 8.0.30
string(2) "/." string(3) "/.." string(6) "/bMrh7"
Output for 8.0.13
string(2) "/." string(3) "/.." string(6) "/bMrh7" string(6) "/1jnHm"
Output for 8.0.1, 8.0.5 - 8.0.6, 8.0.10 - 8.0.12
Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/in): Failed to open directory: Permission denied in /in/bMrh7:12 Stack trace: #0 /in/bMrh7(12): RecursiveDirectoryIterator->__construct('/in') #1 /in/bMrh7(110): Bug\Directory->__construct('/in') #2 {main} thrown in /in/bMrh7 on line 12
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6, 7.3.12, 7.3.30 - 7.3.32, 7.4.0, 7.4.19 - 7.4.20, 7.4.23 - 7.4.25
Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(/in): failed to open dir: Permission denied in /in/bMrh7:12 Stack trace: #0 /in/bMrh7(12): RecursiveDirectoryIterator->__construct('/in') #1 /in/bMrh7(110): Bug\Directory->__construct('/in') #2 {main} thrown in /in/bMrh7 on line 12
Process exited with code 255.
Output for 7.4.22
string(2) "/." string(3) "/.." string(6) "/4EFmi" string(6) "/bMrh7"
Output for 7.4.5
string(2) "/." string(3) "/.." string(6) "/AC7o2" string(6) "/l0497" string(6) "/XLPqK" string(6) "/2qkMN" string(6) "/b38AK" string(6) "/trdbO" string(6) "/vZQI9" string(6) "/miIkG" string(6) "/njNEJ" string(6) "/V9CJc" string(6) "/KEPp9" string(6) "/bMrh7" string(6) "/4ftC7" string(6) "/fuGFf" string(6) "/uqAm4" string(6) "/QN9uW"
Output for 7.4.4
string(2) "/." string(3) "/.." string(6) "/V9CJc" string(6) "/njNEJ" string(6) "/KEPp9" string(6) "/4ftC7" string(6) "/bMrh7" string(6) "/fuGFf" string(6) "/uqAm4"
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.36, 5.6.0 - 5.6.28
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/in): failed to open dir: Permission denied' in /in/bMrh7:12 Stack trace: #0 /in/bMrh7(12): RecursiveDirectoryIterator->__construct('/in') #1 /in/bMrh7(110): Bug\Directory->__construct('/in') #2 {main} thrown in /in/bMrh7 on line 12
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_STRING in /in/bMrh7 on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING in /in/bMrh7 on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/bMrh7 on line 2
Process exited with code 255.

preferences:
264.85 ms | 401 KiB | 347 Q