# PHP7 scalar type hint error bug?

- Thread: https://externals.io/message/86215
- Original archive: https://news-web.php.net/php.internals/86215
- Started by Yasuo Ohgaki on 2015-05-14T09:46:40+00:00
- Messages: 3
- RFC: Scalar Type Hints v0.5 (Implemented (PHP 7.0)) — https://externals.io/rfc/scalar_type_hints_v5.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #86215 — Yasuo Ohgaki — 2015-05-14T09:46:40+00:00

URL: https://externals.io/message/86215#86215

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.


Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #86216 — Nikita Popov — 2015-05-14T09:51:23+00:00

URL: https://externals.io/message/86215#86216 · In reply to: #86215

> 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

---

## #86218 — Yasuo Ohgaki — 2015-05-14T10:43:06+00:00

URL: https://externals.io/message/86215#86218 · In reply to: #86216

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
