On Thu, May 14, 2015 at 11:46 AM, Yasuo Ohgaki <yohg...@ohgaki.net> wrote:

> Hi Anthony,
>
> I'm experimenting type hints to write how it could be useful.
>
> http://3v4l.org/nhI61
>
> I thought too large value error in weak mode is E_RECOVERABLE_ERROR,
> but it's not. The RFC ( https://wiki.php.net/rfc/scalar_type_hints_v5 )
> does not
> state how it behaves for too large values.
>
> E_ERROR is too severe for too large values. Behavior like this
>
> http://3v4l.org/avsW4
>
> is preferred because it's much easier to handle errors nicely.
>
> E_ERROR is too severe even for strict_types=1, IMHO, because
> user does not have chance to handle errors nicely at all.
>
> http://3v4l.org/aEpP8
>
> Is this behavior is agreed behavior by discussion or a bug?
>
> In the RFC
>
> https://wiki.php.net/rfc/scalar_type_hints_v5#behaviour_of_strict_type_checks
> it says
>
> ---------------------
> Behaviour of strict type checks
>
> A strictly type-checked call to an extension or built-in PHP function
> changes the behaviour of zend_parse_parameters. In particular, it will
> produceE_RECOVERABLE_ERROR rather than E_WARNING on failure, and it follows
> strict type checking rules for scalar typed parameters, rather than the
> traditional weak type checking rules.
> ---------------------
>
> It seems intended error level is E_WARNING/E_RECOVERABLE_ERROR according to
> the RFC.
>

The output is a bit confusing: This will actually throw a TypeException,
it's just currently rendered like a fatal error (known issue, will have to
be resolved at some point). If you wrap your code with a catch
(TypeException $e) you'll be able to handle argument type errors - this
includes both errors for user typehints and for internal function types.

Nikita

Reply via email to