$callback =
            function ($quantity, $product) use ($tax, &$total)
            {
                $pricePerItem = constant(__CLASS__ . "::PRICE_" .
                    strtoupper($product));
                $total += ($pricePerItem * $quantity) * ($tax + 1.0);
            };其中的use和__CLASS__是什么.谢谢

解决方案 »

  1.   

    __CLASS__ //这个指当前类名   要是你上面的这个函数要是在class objectClass,那么 
    __CLASS__ 就是objectClsss
    use 命名空间别名  命名空间别名可能是最有用的构想了,别名允许我们使用较短的名称引用很长的命名空间use App\Lib1 as L;   
    use App\Lib2\MyClass as Obj;header('Content-type: text/plain');   
    require_once('lib1.php');   
    require_once('lib2.php');   
      
    echo L\MYCONST . "\n";   
    echo L\MyFunction() . "\n";   
    echo L\MyClass::WhoAmI() . "\n";   
    echo Obj::WhoAmI() . "\n";
      

  2.   

    我也不是很明白这个use的使用,请懂得这个使用的高人出来讲解下啊。。在哪里使用,最好分析说明下这样使用的好处。。
      

  3.   

    php 5.3新特性 “闭包”从外部环境中导入的变量是在闭包函数定义的 use 子句中指定的。试试这俩段代码的结果你就知道了code1:
    $string = "Hello World!";
    $closure = function() use ($string) { echo $string; };
    $closure();code2:
    $string = "Hello World!";
    $closure = function(){ echo $string; };
    $closure();
      

  4.   

    显示  $closure = function() use($string){ echo $string; };
    有语法错误;