Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The PHP group use statement is a syntactic construct introduced in PHP 7.0 that allows multiple classes, functions, or constants originating from the same base namespace to be imported into the current scope using a single use declaration. It eliminates redundant namespace prefixes by encapsulating the shared namespace path and grouping the specific imported entities within curly braces {}.

Syntax Mechanics

The fundamental syntax requires defining the common base namespace, followed by a trailing backslash \, and a comma-separated list of the target entities enclosed in curly braces.
use Base\Namespace\Path\{EntityOne, EntityTwo, EntityThree};
This is strictly equivalent to writing multiple individual use statements:
use Base\Namespace\Path\EntityOne;
use Base\Namespace\Path\EntityTwo;
use Base\Namespace\Path\EntityThree;

Aliasing within Groups

The as keyword can be applied to individual entities within the group block to resolve naming collisions or provide local aliases. The alias applies only to the specific entity it follows.
use Vendor\Package\Http\{
    Request,
    Response as HttpResponse,
    Middleware\Auth as AuthMiddleware
};

Type Specifiers (Functions and Constants)

Group use statements support importing functions and constants. The type specifier (function or const) can be applied at the base level if all grouped entities share the same type. Grouping Functions:
use function Math\Geometry\{calculateArea, calculateVolume};
Grouping Constants:
use const Math\Constants\{PI, EULER_NUMBER};

Mixed Import Types

A single group use statement can import a combination of classes, functions, and constants from the same base namespace. When mixing types, the base use statement remains untyped (defaulting to class imports), and the function or const specifiers are applied directly to the individual entities inside the curly braces.
use App\Core\System\{
    Config,                  // Imports the Config class
    function initialize,     // Imports the initialize() function
    const VERSION            // Imports the VERSION constant
};

Trailing Commas

As of PHP 7.2, group use statements support a trailing comma inside the curly braces. This is a purely syntactic allowance designed to simplify version control diffs when modifying multiline import blocks.
use Illuminate\Support\Facades\{
    Cache,
    DB,
    Log, // Trailing comma permitted in PHP >= 7.2
};
Master PHP with Deep Grasping Methodology!Learn More