Reputation: 906
I saw this snippet and I dont understand why used
use function array_map
expression ?
<?php
namespace Project\MyProject;
use function array_map;
class MyProjectClass
{
protected $arr = [];
public function __construct(array $arr)
{
$this->arr = array_map('trim', $arr);
}
}
Upvotes: 3
Views: 1636
Reputation: 145512
As mentioned in how to call global functions classes from namespace PHP:
use function array_map;
aliases a global function into the local namespace.
use function
.The real reason use function
was introduced is:
For actually aliasing / renaming functions:
use function App\Helpers\my_mappymcmapface as array_map;
use function \trim as chomp;
And also because PHP coders have been littering their codebases with \trim
and \strpos
before.
So yes, for this case it's pointless decoration.
Upvotes: 7