Welcome! Log In Create A New Profile

Advanced

[PHP-DEV] Confusing type mismatch error messages

Posted by Christoph M. Becker 
Christoph M. Becker
[PHP-DEV] Confusing type mismatch error messages
September 20, 2017 05:30PM
Hi everybody!

If a type declaration inadvertently uses `boolean` or `integer` (instead
of `bool` and `int`, respectively), the error message is rather confusing:

[…] must be an instance of boolean, boolean given, […]

This issue has been filed as https://bugs.php.net/65656, and Adam
submitted https://github.com/php/php-src/pull/442 to fix that, but
David hinted at the potential BC break, and Joe closed the PR later
stating that such change would require an RFC.

In my opinion, it would be sufficient to change the error message so
that the canonical name of the type would be used, i.e. `bool` and
`int`, respectively, so the message above would read:

[…] must be an instance of boolean, bool given, […]

This change would still be a BC break, but at a far smaller scale than
Adam's PR would have been.

So I am asking for opinions whether this change would be worth the BC
break, and whether a respective RFC could target PHP 7.3, or would have
to wait for PHP 8.

--
Christoph M. Becker

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Derick Rethans
Re: [PHP-DEV] Confusing type mismatch error messages
September 20, 2017 07:00PM
On Wed, 20 Sep 2017, Christoph M. Becker wrote:

> Hi everybody!
>
> If a type declaration inadvertently uses `boolean` or `integer` (instead
> of `bool` and `int`, respectively), the error message is rather confusing:
>
> […] must be an instance of boolean, boolean given, […]
>
> This issue has been filed as https://bugs.php.net/65656, and Adam
> submitted https://github.com/php/php-src/pull/442 to fix that, but
> David hinted at the potential BC break, and Joe closed the PR later
> stating that such change would require an RFC.
>
> In my opinion, it would be sufficient to change the error message so
> that the canonical name of the type would be used, i.e. `bool` and
> `int`, respectively, so the message above would read:
>
> […] must be an instance of boolean, bool given, […]

Or why not:

[…] must be an instance of class boolean, boolean given, […]

but I guess we then need to also use "trait" or "interface" as words
there too.

cheers,
Derick
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Christoph M. Becker
Re: [PHP-DEV] Confusing type mismatch error messages
September 20, 2017 07:10PM
On 20.09.2017 at 18:54, Derick Rethans wrote:

> On Wed, 20 Sep 2017, Christoph M. Becker wrote:
>
>> This issue has been filed as https://bugs.php.net/65656, and Adam
>> submitted https://github.com/php/php-src/pull/442 to fix that, but
>> David hinted at the potential BC break, and Joe closed the PR later
>> stating that such change would require an RFC.
>>
>> In my opinion, it would be sufficient to change the error message so
>> that the canonical name of the type would be used, i.e. `bool` and
>> `int`, respectively, so the message above would read:
>>
>> […] must be an instance of boolean, bool given, […]
>
> Or why not:
>
> […] must be an instance of class boolean, boolean given, […]
>
> but I guess we then need to also use "trait" or "interface" as words
> there too.

That has been suggested by Adam, but 62 tests had to be modified,
pointing out the magnitude of this change. And actually, I still would
be surprised to see such an error message. It should not be possible to
have a class/interface with the same name as a scalar type – and
actually it is not.

--
Christoph M. Becker

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Anonymous User
Re: [PHP-DEV] Confusing type mismatch error messages
September 20, 2017 07:20PM
> And actually, I still would be surprised to see such an error message.

This happens when you annotate your function incorrectly:
https://3v4l.org/CoUss


On 20 Sep 2017, 19:08 +0200, Christoph M. Becker <[email protected]>, wrote:
> On 20.09.2017 at 18:54, Derick Rethans wrote:
>
> > On Wed, 20 Sep 2017, Christoph M. Becker wrote:
> >
> > > This issue has been filed as https://bugs.php.net/65656, and Adam
> > > submitted https://github.com/php/php-src/pull/442 to fix that, but
> > > David hinted at the potential BC break, and Joe closed the PR later
> > > stating that such change would require an RFC.
> > >
> > > In my opinion, it would be sufficient to change the error message so
> > > that the canonical name of the type would be used, i.e. `bool` and
> > > `int`, respectively, so the message above would read:
> > >
> > > […] must be an instance of boolean, bool given, […]
> >
> > Or why not:
> >
> > […] must be an instance of class boolean, boolean given, […]
> >
> > but I guess we then need to also use "trait" or "interface" as words
> > there too.
>
> That has been suggested by Adam, but 62 tests had to be modified,
> pointing out the magnitude of this change. And actually, I still would
> be surprised to see such an error message. It should not be possible to
> have a class/interface with the same name as a scalar type – and
> actually it is not.
>
> --
> Christoph M. Becker
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Sorry, only registered users may post in this forum.

Click here to login