3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function loadClass($name) { $className = ltrim($name, '\\'); if($lastNsPos = strrpos($className, '\\')) { /*имеется namespace, значит vendor*/ $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = __DIR__.'/../../vendor/'; $fileName .= str_replace('\\', '/', $namespace).'/'; } else { /*в modules */ $fileName = __DIR__.'/../'; $is_controller=false; if(strpos($className, 'c_') === 0) { $is_controller = true; $className = substr($className, strlen('c_') + 1); } if(strpos($className, '_')!==false) { $className = str_replace('_', '/', $className); } else { if($is_controller) { $className = $className.'/'.'c_'.$className; } else { $className = $className.'/'.$className; } } } $fileName .= $className.'.class.php'; //Здесь именно include, т.к. require вывалит фатальную ошибку echo $fileName; echo "\n"; } loadClass('sdf_fdffd_ffff'); loadClass('sdf'); loadClass('c_sdf_fdffd_ffff'); loadClass('c_sdf'); loadClass('c\sdf\5tttt');
Output for 5.3.0 - 7.1.0
/in/../sdf/fdffd/ffff.class.php /in/../sdf/sdf.class.php /in/../df/fdffd/ffff.class.php /in/../df/c_df.class.php /in/../../vendor/c/sdf/5tttt.class.php
Output for 4.3.0 - 5.2.17
Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/RXM7c on line 12 __DIR__/../sdf/fdffd/ffff.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/RXM7c on line 12 __DIR__/../sdf/sdf.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/RXM7c on line 12 __DIR__/../df/fdffd/ffff.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/RXM7c on line 12 __DIR__/../df/c_df.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/RXM7c on line 8 __DIR__/../../vendor/c/sdf/5tttt.class.php