PHP 7 - use Statement


Advertisements

From PHP7 onwards, a single use statement can be used to import Classes, functions and constants from same namespace instead of multiple use statements.

Example

<?php
   // Before PHP 7
   use com\howcodex\ClassA;
   use com\howcodex\ClassB;
   use com\howcodex\ClassC as C;

   use function com\howcodex\fn_a;
   use function com\howcodex\fn_b;
   use function com\howcodex\fn_c;

   use const com\howcodex\ConstA;
   use const com\howcodex\ConstB;
   use const com\howcodex\ConstC;

   // PHP 7+ code
   use com\howcodex\{ClassA, ClassB, ClassC as C};
   use function com\howcodex\{fn_a, fn_b, fn_c};
   use const com\howcodex\{ConstA, ConstB, ConstC};

?>
Advertisements