>  기사  >  백엔드 개발  >  PHP有没有USE这个关键词解决方案

PHP有没有USE这个关键词解决方案

WBOY
WBOY원래의
2016-06-13 13:34:04774검색

PHP有没有USE这个关键词
我看的一些PHP的资料好像都没有USE。但是刚才看一个框架时发现里面用到了USE。

------解决方案--------------------
我猜 没有吧
------解决方案--------------------
这个不明白啊
------解决方案--------------------
namespace foo;
use My\Full\Classname as Another;

// this is the same as use My\Full\NSname as NSname
use My\Full\NSname;

// importing a global class
use ArrayObject;

$obj = new namespace\Another; // instantiates object of class foo\Another
$obj = new Another; // instantiates object of class My\Full\Classname
NSname\subns\func(); // calls function My\Full\NSname\subns\func
$a = new ArrayObject(array(1)); // instantiates object of class ArrayObject
// without the "use ArrayObject" we would instantiate an object of class foo\ArrayObject
?>
好像是给一个类定义别名:如下

use class3 as Another;
use class3 as Another1;
use class3 as Another2;

$obj = new Another; //
$obj = new Another1; // 
$obj = new Another2; //

------解决方案--------------------
php 5.3+

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.