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

解决方案 »

  1.   

    查阅 php  命名空间相关资料.
      

  2.   

    是关键字。
    http://www.php.net/manual/zh/reserved.keywords.php
    http://php.net/manual/en/language.namespaces.importing.php
      

  3.   

    <?php
    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; //
      

  4.   

    php 5.4中用use来获取Traits中的方法和属性
      

  5.   

    php5.3+闭包
    <?php
    $msg = "world";
    $callback = function ($var) use ($msg) {
        echo $var,$msg;
    };
    $callback('hello ');