<?php declare(strict_types=1); class Test { public static function valid(?float $value): bool { if ($value !== null && !is_float($value)) throw new InvalidArgumentException('Not valid'); return true; } } var_dump(Test::valid('1.2')); // "valid" because of implicit typecast, which can disabled with declare strict_types var_dump(Test::valid('not a number')); // triggers TypeError, NOT InvalidArgumentException
You have javascript disabled. You will not be able to edit any code.