3v4l.org

run code in 300+ PHP versions simultaneously
<?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; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<pre>input \Library\Database::doQuery icr: Fatal error: Uncaught Error: Undefined constant "ROOT" in /in/BIbEg:23 Stack trace: #0 /in/BIbEg(64): {closure}('\\Library\\Databa...') #1 {main} thrown in /in/BIbEg on line 23
Process exited with code 255.
Output for 7.2.0, 7.3.32 - 7.3.33, 7.4.33
<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 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.32
<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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//library/database::doquery.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//vendor/twilio-php/x.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//namespace/package/class_name.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//namespace/package_name/class_name.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BIbEg on line 30 psr: namespace/package_name/Class/Name.php
Output for 7.2.6
<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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//library/database::doquery.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//vendor/twilio-php/x.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//namespace/package/class_name.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//namespace/package_name/class_name.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 psr: namespace/package_name/Class/Name.php
Output for 7.1.20
<pre>input \Library\Database::doQuery icr: Notice: Use of undefined constant ROOT - assumed 'ROOT' in /in/BIbEg on line 23 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//library/database::doquery.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//vendor/twilio-php/x.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//namespace/package/class_name.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 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 Warning: is_readable(): open_basedir restriction in effect. File(ROOT//namespace/package_name/class_name.php) is not within the allowed path(s): (/tmp:/in) in /in/BIbEg on line 30 psr: namespace/package_name/Class/Name.php
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 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

preferences:
205.61 ms | 404 KiB | 227 Q