English 中文(简体)
PHP 7 - use Statement
  • 时间:2024-11-03

PHP 7 - use Statement


Previous Page Next Page  

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	utorialspointClassA;
   use com	utorialspointClassB;
   use com	utorialspointClassC as C;

   use function com	utorialspointfn_a;
   use function com	utorialspointfn_b;
   use function com	utorialspointfn_c;

   use const com	utorialspointConstA;
   use const com	utorialspointConstB;
   use const com	utorialspointConstC;

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

?>
Advertisements