Sometimes in some libraries like thephpleague/csv
, I see the use
keyword to import core identifiers (e.g. functions, classes or constants) but I can't understand why they are being imported at all.
See the following example:
use Generator;
use SplFileObject;
use function filter_var;
use function get_class;
use function mb_strlen;
use function rawurlencode;
use function sprintf;
use function str_replace;
use function str_split;
use function strcspn;
use function strlen;
use const FILTER_FLAG_STRIP_HIGH;
use const FILTER_FLAG_STRIP_LOW;
use const FILTER_SANITIZE_STRING;
Or more from here.
These classes, functions and constants that are imported in this file are belong to PHP core, so we wouldn't actually need to import them.
Why this and other libraries import these?