WEB DEVELOPER SITE
PYTHON
 

PHP 7 Scalar Type Declarations


This is a new feature of Php 7


scalar type declaration are two type.

  • strict: this mode explicitly hinted.
  • coercive : need not to be specified.

Example - Strict Mode

Example

<?php
   // Strict mode
   declare(strict_types=1);
   function sum(int ...$ints) {
      return array_sum($ints);
   }
   print(sum(4, '5', 6.1));
?>
Try it yourself »

Example - Coercive Mode

Example

<?php

   // Coercive mode
   function sum(int ...$ints) {
      return array_sum($ints);
   }
   print(sum(1, '2', 3.1));

?>
Try it yourself »
OUTPUT 6