3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = function($className) { if (strpos($className, '\\') !== false) { $parts = array_map('strtolower', array_values(explode('\\', $className))); $count = count($parts); $folder = $file = ''; while ($count--) { if ($count >= 1) { $folder .= array_shift($parts) . ($count > 1 ? '/' : ''); } else { $file = array_shift($parts); } } // Not really a great idea if (substr($folder, 0, 3) == 'api') { $folder = str_replace('api', 'controller/api', $folder); } $fileName = ROOT . '/' . $folder . '/' . $file . '.php'; // Reroute \<namespace>\exception.php -> \library\exception.php if ($file == "exception" && $className != 'API\Exception') { $fileName = ROOT . '/library/exception.php'; } if (is_readable($fileName)) { return $fileName; return true; } } return false; }; $b = function($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; return $fileName; }; $tests = [ '\Library\Database::doQuery', '\Vendor\twilio-php\x', '\namespace\package\Class_Name', '\namespace\package_name\Class_Name' ]; echo '<pre>'; foreach ($tests as $test) { echo 'input ', $test, PHP_EOL; echo 'icr: ', $a($test), PHP_EOL; echo 'psr: ', $b($test), PHP_EOL; }
based on aX7HL
Output for 7.2.0
<pre>input \Library\Database::doQuery icr: Warning: Use of undefined constant ROOT - assumed 'ROOT' (this will throw an Error in a future version of PHP) in /in/BIbEg on line 23 psr: Library/Database::doQuery.php input \Vendor\twilio-php\x icr: Warning: Use of undefined constant ROOT - assumed 'ROOT' (this will throw an Error in a future version of PHP) in /in/BIbEg on line 23 psr: Vendor/twilio-php/x.php input \namespace\package\Class_Name icr: Warning: Use of undefined constant ROOT - assumed 'ROOT' (this will throw an Error in a future version of PHP) in /in/BIbEg on line 23 psr: namespace/package/Class/Name.php input \namespace\package_name\Class_Name icr: Warning: Use of undefined constant ROOT - assumed 'ROOT' (this will throw an Error in a future version of PHP) in /in/BIbEg on line 23 psr: namespace/package_name/Class/Name.php
Output for 5.4.1 - 7.1.10
<pre>input \Library\Database::doQuery icr: Notice: Use of undefined constant ROOT - assumed 'ROOT' in /in/BIbEg on line 23 psr: Library/Database::doQuery.php input \Vendor\twilio-php\x icr: Notice: Use of undefined constant ROOT - assumed 'ROOT' in /in/BIbEg on line 23 psr: Vendor/twilio-php/x.php input \namespace\package\Class_Name icr: Notice: Use of undefined constant ROOT - assumed 'ROOT' in /in/BIbEg on line 23 psr: namespace/package/Class/Name.php input \namespace\package_name\Class_Name icr: Notice: Use of undefined constant ROOT - assumed 'ROOT' in /in/BIbEg on line 23 psr: namespace/package_name/Class/Name.php
Output for 5.3.17 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/BIbEg on line 54
Process exited with code 255.