$callback =
function ($quantity, $product) use ($tax, &$total)
{
$pricePerItem = constant(__CLASS__ . "::PRICE_" .
strtoupper($product));
$total += ($pricePerItem * $quantity) * ($tax + 1.0);
};其中的use和__CLASS__是什么.谢谢
function ($quantity, $product) use ($tax, &$total)
{
$pricePerItem = constant(__CLASS__ . "::PRICE_" .
strtoupper($product));
$total += ($pricePerItem * $quantity) * ($tax + 1.0);
};其中的use和__CLASS__是什么.谢谢
__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";
$string = "Hello World!";
$closure = function() use ($string) { echo $string; };
$closure();code2:
$string = "Hello World!";
$closure = function(){ echo $string; };
$closure();
有语法错误;