Home  >  Article  >  php教程  >  php命名空间(namespace)内如何使用系统类

php命名空间(namespace)内如何使用系统类

WBOY
WBOYOriginal
2016-06-06 19:44:181321browse

作者:ffsystem 使用命名空间,可以更方便的组织代码,以及代码复用。新写的一个项目引入了命名空间。 简介:使用namespace,使用__autoload自动导入类。 今天将以前的一段代码,加入到新项目时,出现了奇怪的问题: 代码中有一行: $this-db=new mysqli(***)

作者:ffsystem

使用命名空间,可以更方便的组织代码,以及代码复用。新写的一个项目引入了命名空间。

简介:使用namespace,使用__autoload自动导入类。

今天将以前的一段代码,加入到新项目时,出现了奇怪的问题:

代码中有一行:

$this->db=new mysqli(***);

错误提示:

Warning: require(FFSystem/mysqli.php): failed to open stream: No such file or directory in **** on line **
Fatal error: require(): Failed opening required 'FFSystem/mysqli.php' (include_path=***) in *** on line **

mysqli是系统类,以前使用出没出现过这种要引用定义文件的问题。

解决办法:

查询了英文网站1找到答案,当在命名空间内使用系统类时需要使用use 引入,或者将代码修改成:

$this->db=new \mysqli(***);

参考文献:

1.http://stackoverflow.com/questions/8662623/how-to-use-mysqli-inside-a-namespace

 


http://www.cnblogs.com/ffsystem/p/4023159.html

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn