我看到了这个片段,我不明白为什么使用use function array_map表达式?
<?php
namespace Project\MyProject;
use function array_map;
class MyProjectClass
{
protected $arr = [];
public function __construct(array $arr)
{
$this->arr = array_map('trim', $arr);
}
}发布于 2018-08-23 14:09:53
正如how to call global functions classes from namespace PHP中提到的
use function array_map;将全局函数别名到本地命名空间中。
use function来破坏它。
引入use function的真正原因是:
- `use function App\Helpers\my_mappymcmapface as array_map;`
- `use function \trim as chomp;`
\trim和\strpos乱扔他们的代码库。- That was one of those unwarranted micro-performance optimizations.
所以是的,对这个案子来说,这是毫无意义的装饰。
https://stackoverflow.com/questions/51970332
复制相似问题