PHP VERSION: 8.2.18

type_hinting_return.php

<?php
// data type the return value

// NOTE: this works even if "declare(strict_types=1);" is missing!

function foo($a): array 
{
    return 
$a;
}

var_dump(foo([1,2,3]));
var_dump(foo('test'));

Output


array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

Unknown Error or Exception!
SOURCE CODE