Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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 - Fatal编程技术网

Php 错误:无故调用类

Php 错误:无故调用类,php,Php,错误是: 找不到类“控制器\索引” 但在我所有的代码中,我随时调用这个类: Test.php 为此,我们希望有一个这样的文件 sample.php namespace Controller; class User { public static function getWorld() { ... } } user.controller.php namespace Controller{ include_once (__DIR__ ."/../index.engine.p

错误是:

找不到类“控制器\索引”

但在我所有的代码中,我随时调用这个类:

Test.php 为此,我们希望有一个这样的文件

sample.php

namespace Controller;

class User {
   public static function getWorld() {
     ...
   }
}

user.controller.php

namespace Controller{
include_once (__DIR__ ."/../index.engine.php");
Index::importPersistent();
use Persistent\Test;
    class User{ 
        public static function getWorld(){
            $result = Test::getEngine(); 
            return $result;
        }
    }
}
我改为:

namespace Controller{
use Index;
use Persistent\Test;
Index::importPersistent();
    class User{ 
        public static function getWorld(){
            $result = Test::getEngine(); 
            return $result;
        }
    }
}

错误出现在多次调用的include中,然后更改为在视图中仅调用一次。

是的,没错,但我想调用控件并运行命令。。。问题是他正试图导入“索引”,而我不想要它。如果我没弄错,你想从控制器调用getWorld()方法,对吗?--我正在从测试文件的控件调用该方法;正在尝试再次获取“索引”,但由于行名称空间控制器;然后创建一个不存在的类。问题是索引并没有停止运行,而是试图包含所有外部类,甚至包括已经包含的索引。。。
namespace Persistent{
    class Test{
        public static function getEngine(){
            $engine = "Engine is on! \o/";
            return $engine;
        }
    }
}
use Controller\User; # this is used to call a namespace, in your code there is no declaration of the namespace
echo User::getWorld(); // 
namespace Controller;

class User {
   public static function getWorld() {
     ...
   }
}
namespace Controller{
include_once (__DIR__ ."/../index.engine.php");
Index::importPersistent();
use Persistent\Test;
    class User{ 
        public static function getWorld(){
            $result = Test::getEngine(); 
            return $result;
        }
    }
}
namespace Controller{
use Index;
use Persistent\Test;
Index::importPersistent();
    class User{ 
        public static function getWorld(){
            $result = Test::getEngine(); 
            return $result;
        }
    }
}