Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的名称空间_Php_Namespaces_Traits_Spl Autoload Register - Fatal编程技术网

PHP中的名称空间

PHP中的名称空间,php,namespaces,traits,spl-autoload-register,Php,Namespaces,Traits,Spl Autoload Register,请看这个,告诉我你对此有何看法: 1) 我有这样的结构: 2)和代码: 它是Index.php,它的作品: <?php namespace Classes; // ^ It doesn't work but when I replace "Classes" to "Test\Classes" It works! // But why? Class Someclass { us

请看这个,告诉我你对此有何看法:

1) 我有这样的结构: 2)和代码: 它是Index.php,它的作品:

<?php
        namespace Classes; 
       // ^ It doesn't work but when I replace "Classes" to "Test\Classes" It 
           works!
        // But why?
      Class Someclass
       {
         use Traits/Sometrait;
          //Yeah, It doesn't work too and when I replace "traits" to "Test\Traits" It  works!
         // Why? =(
          public static function start() {...}
      }
      ?>
**
它是Someclass.php:

<?php
        namespace Classes; 
       // ^ It doesn't work but when I replace "Classes" to "Test\Classes" It 
           works!
        // But why?
      Class Someclass
       {
         use Traits/Sometrait;
          //Yeah, It doesn't work too and when I replace "traits" to "Test\Traits" It  works!
         // Why? =(
          public static function start() {...}
      }
      ?>

您遗漏了最重要的部分。。
里面有什么

spl_autoload_register(...);
?

这里设置的函数将决定如何在项目目录中找到类

看看这个

spl_autoload_register(...);