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__.'/../'; if(strpos($className, 'c_') === 0) { //контроллер $className = substr($className, strlen('c_')); $className = $className.'/'.'c_'.$className; } elseif(strpos($className, '_') !== false) { //подкласс $className = str_replace('_', '/', $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');
based on KspbA
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
/in/../sdf/fdffd/ffff.class.php /in/../sdf/sdf.class.php /in/../sdf_fdffd_ffff/c_sdf_fdffd_ffff.class.php /in/../sdf/c_sdf.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/PTfb6 on line 12 __DIR__/../sdf/fdffd/ffff.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/PTfb6 on line 12 __DIR__/../sdf/sdf.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/PTfb6 on line 12 __DIR__/../sdf_fdffd_ffff/c_sdf_fdffd_ffff.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/PTfb6 on line 12 __DIR__/../sdf/c_sdf.class.php Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /in/PTfb6 on line 8 __DIR__/../../vendor/c/sdf/5tttt.class.php