Hi internals,
I'd like to bring forward the following proposal for PHP 8, which will make
(zpp) parameter parsing failures always result in a TypeError (rather than
generating a warning+null, depending on circumstances):
https://wiki.php.net/rfc/consistent_type_errors
The goal here is to remove one of the inconsistencies between user-defined
and internal functions, and to put us in a position where we can actually
start specifying type information in arginfo without fear of breaking
things.
Regards,
Nikita
Hi internals,
I'd like to bring forward the following proposal for PHP 8, which will make
(zpp) parameter parsing failures always result in a TypeError (rather than
generating a warning+null, depending on circumstances):https://wiki.php.net/rfc/consistent_type_errors
The goal here is to remove one of the inconsistencies between user-defined
and internal functions, and to put us in a position where we can actually
start specifying type information in arginfo without fear of breaking
things.Regards,
Nikita
I'm all for it but what is the scope of the RFC?
Is it all core functions, bundled extension functions, or all extension
functions?
Also does this means that there will be argument type hinting in core
functions that
could be found out via reflection?
Best regards
George P. Banyard
Hi internals,
I'd like to bring forward the following proposal for PHP 8, which will
make
(zpp) parameter parsing failures always result in a TypeError (rather than
generating a warning+null, depending on circumstances):https://wiki.php.net/rfc/consistent_type_errors
The goal here is to remove one of the inconsistencies between user-defined
and internal functions, and to put us in a position where we can actually
start specifying type information in arginfo without fear of breaking
things.Regards,
NikitaI'm all for it but what is the scope of the RFC?
Is it all core functions, bundled extension functions, or all extension
functions?
It affects all internal functions using the zpp APIs, which covers pretty
much all core functions, bundled extension functions and third-party
extension functions.
Also does this means that there will be argument type hinting in core
functions that
could be found out via reflection?
Not as a direct result of the proposal, but the RFC does remove the big
blocker for it. Once it lands we need one more change (don't actually
verify arginfo types for internal functions to avoid double type checking),
and then we can start adding the necessary type information. That will also
take some work, as we have many functions, but it's something everyone can
help with.
Nikita
[. . .]
I'm all for it but what is the scope of the RFC?
Is it all core functions, bundled extension functions, or all extension
functions?It affects all internal functions using the zpp APIs, which covers pretty
much all core functions, bundled extension functions and third-party
extension functions.
Thanks for the clarification, that's great
Also does this means that there will be argument type hinting in core
functions that
could be found out via reflection?Not as a direct result of the proposal, but the RFC does remove the big
blocker for it. Once it lands we need one more change (don't actually
verify arginfo types for internal functions to avoid double type checking),
and then we can start adding the necessary type information. That will also
take some work, as we have many functions, but it's something everyone can
help with.Nikita
I suppose if this RFC gets voted (and implemented) there should be enough
(maybe I'm wrong) time to also implement this.
Really like this RFC even with the potential BC break as there are Static
analysis tools (such as PHPStan, Psalm and forgot the third major one)
which can help point out potential type errors.
Best regards
George P. Banyard
Hi Nikita,
Nikita Popov wrote:
I'd like to bring forward the following proposal for PHP 8, which will make
(zpp) parameter parsing failures always result in a TypeError (rather than
generating a warning+null, depending on circumstances):
I like this proposal. IMO PHP's E_WARNING
+ NULL
is the worst of its
“Keep Calm and Carry On” (sorry) behaviours, it would be nice to get rid
of it for good, rather than just in the comfy world of strict_types=1.
The goal here is to remove one of the inconsistencies between user-defined
and internal functions, and to put us in a position where we can actually
start specifying type information in arginfo without fear of breaking
things.
Regrettably, as I pointed out to you via another channel, that idea also
faces the problem of the other deliberate inconsistency I am responsible
for in userland scalar type declarations, namely that the non-nullable
variety of those reject null as a valid value, unlike internal functions
which will happily coerce it. It's funny to mention this here, as the
E_WARNING
+ NULL
behaviour your RFC would drop was a primary
justification of mine for making NULL
special here. Unfortunately it's
not the only case, I'm sure uncountably much PHP code relies on things
like strlen($_GET['nonexistent']) working… but I digress.
Thanks,
Andrea
Hi Nikita
https://wiki.php.net/rfc/consistent_type_errors
Would it make sense and be possible to trigger a deprecation notice in PHP
7.4?
That might help the ecosystem move forward in a smooth way instead of
experimenting the failure when actually moving to 8.
Nicolas
On Wed, Feb 6, 2019 at 7:30 AM Nicolas Grekas nicolas.grekas@gmail.com
wrote:
Hi Nikita
https://wiki.php.net/rfc/consistent_type_errors
Would it make sense and be possible to trigger a deprecation notice in PHP
7.4?That might help the ecosystem move forward in a smooth way instead of
experimenting the failure when actually moving to 8.Nicolas
I don't think so. We generally consider a warning a "harder" error than a
deprecation (unlike deprecations, they are part of the default
error_reporting level), so I don't think replacing or adding a deprecation
would do much here. The only way you can be unaware of problems resulting
from this change is if you are deliberately suppressing warnings, in which
case chances are very good that you are also suppressing deprecations.
Nikita
https://wiki.php.net/rfc/consistent_type_errors
Would it make sense and be possible to trigger a deprecation notice in
PHP 7.4?That might help the ecosystem move forward in a smooth way instead of
experimenting the failure when actually moving to 8.We generally consider a warning a "harder" error than a deprecation
Do all situations that will throw after the RFC trigger a warning right
now? Eg var_dump(substr(null, 1)); doesn't trigger anything but returns
false - does that mean it will not throw a TypeError in your proposal?
if you are deliberately suppressing warnings, in which case chances are
very good that you are also suppressing deprecations.
This assumption is wrong in the Symfony ecoystem!
We built the deprecation framework around silenced (and unsilenced)
deprecations, which are all caught and logged.
So it would make a huge difference actually, at least for situations where
no warning is triggered (see substr example above).
Nicolas
On Wed, Feb 6, 2019 at 9:43 AM Nicolas Grekas nicolas.grekas@gmail.com
wrote:
https://wiki.php.net/rfc/consistent_type_errors
Would it make sense and be possible to trigger a deprecation notice in
PHP 7.4?That might help the ecosystem move forward in a smooth way instead of
experimenting the failure when actually moving to 8.We generally consider a warning a "harder" error than a deprecation
Do all situations that will throw after the RFC trigger a warning right
now? Eg var_dump(substr(null, 1)); doesn't trigger anything but returns
false - does that mean it will not throw a TypeError in your proposal?
That's correct, it will not throw a TypeError. If the call currently
succeeds, then it will continue to succeed. substr(null, 1) is considered a
perfectly valid substr()
call right now.
if you are deliberately suppressing warnings, in which case chances are
very good that you are also suppressing deprecations.
This assumption is wrong in the Symfony ecoystem!
We built the deprecation framework around silenced (and unsilenced)
deprecations, which are all caught and logged.
So it would make a huge difference actually, at least for situations where
no warning is triggered (see substr example above).
Right, but a warning is always triggered here. If there were no warning,
then yes, I'd of course agree that this should throw a deprecation first.
Nikita