use gives a fully qualified name a short alias for the rest of the file. It is compile-time substitution only: nothing is loaded or checked. Classes, interfaces, enums and namespaces take plain use; functions and constants need use function and use const.
<?php
namespace Acme\ShopMoney {
const DEFAULT_LOCALE = 'en_US';
enum Currency: string { case USD = 'USD'; }
final class Money { public function __construct(public int $minor) {} }
function money(int $minor): Money { return new Money($minor); }
}
namespace Shop\Checkout {
use Acme\ShopMoney\{Currency, Money as Amount}; // group use with an alias (PHP 7.0)
use function Acme\ShopMoney\money; // a function import (PHP 5.6)
use const Acme\ShopMoney\DEFAULT_LOCALE; // a constant import (PHP 5.6)
use Vendor\Nowhere\Ghost; // never loaded, never checked
$total = money(2499);
echo $total::class, ' ', $total instanceof Amount ? 'is' : 'is not', " an Amount\n";
echo Currency::USD->value, ' ', DEFAULT_LOCALE, ' ', Ghost::class, "\n";
var_dump(class_exists(Ghost::class));
}Output
Acme\ShopMoney\Money is an Amount USD en_US Vendor\Nowhere\Ghost bool(false)
Amount is Money under another name, and Ghost::class expanded without loading anything. Aliases resolve clashes (use Monolog 21,402 \Logger as MonologLogger); two imports under one short name fail with "Cannot use C\Money as Money because the name is already in use". Imports apply to their file only; a closure's use ($x) is the unrelated capture of Subsection 4.4.4.