Hi Anthony,
I'm experimenting type hints to write how it could be useful.
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
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.
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.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Anthony,
I'm experimenting type hints to write how it could be useful.
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 thisis 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.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 thanE_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
Hi Nikita,
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.
Thanks again,
It even worked on 3v4l
http://3v4l.org/sp1C4
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net