[PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2021-09-17 Thread Craig Francis
Hi Internals,

https://externals.io/message/112327
https://externals.io/message/112996

Considering how frequently developers use this pattern:

$name = ($_POST['name'] ?? NULL);

Sometimes without really noticing, e.g.

- Laravel: `$request->input('name');`
- Symfony: `$request->get('name');`
- CakePHP: `$this->request->getQuery('name');`
- CodeIgniter: `$request->getGet('name');`

I'm concerned it's going to make upgrading to 8.1 fairly annoying, as these
NULL values get passed to `strlen()`, `trim()`, `strpos()`,
`htmlspecialchars()`, `strtoupper()`, `hash()`, `simplexml_load_string()`,
`strtotime()`, etc.

I appreciate projects using `strict_types=1` will prefer this, but I
suspect all the deprecation notices will be annoying for the majority of
projects that don't.

And I appreciate that each instance is easy to fix, but there is a lot of
them out there (says he trying out a few projects on 8.1.0RC2, and being
glad that I'm not the one who needs to find and explicitly change all of
these potential NULL values to an empty string).

As an aside, it is useful having NULL to differentiate between a
GET/POST/etc value not being present, vs the value being explicitly set to
an empty string.

And anyone using Laravel, remember that `error_reporting(-1)` is used
in HandleExceptions.php (to report all errors), and E_DEPRECATED is handled
via `ErrorException`, which is likely to result in 500 errors for you...
same with "Return type of X should either be compatible with X, or the
#[\ReturnTypeWillChange] attribute should be used to temporarily suppress
the notice" (lots of those, hopefully all will be fixed soon).

Craig


Re: [PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2021-01-07 Thread Nikita Popov
On Wed, Dec 16, 2020 at 10:50 PM Craig Duncan  wrote:

> While making internal functions treat non-nullable types consistently with
> userland is an absolute win,
> I do wonder if it should be done simultaneously with changing some
> functions
> to formally accept nulls.
>

PHP 8 made quite a few function/method arguments nullable to fix various
behavior consistency issues. That said...

I'm thinking back to all the pain caused when *count() *starting raising a
> warning for null values.
> We saw a lot of code that passed undeclared variables to *count()*
> and I can imagine people writing similar code with something like
> *strlen()*
>

I don't think that making the argument of strlen() nullable is in any way
appropriate. This is a case where people will just have to fix their code.
I do think we can relax certain type requirements on a case by case basis
(e.g. the fact that ini_set requires a string rather than any scalar value
seems unnecessarily pedantic), this just isn't one of those cases.
Generally making arguments nullable mostly applies to arguments that are
optional.

Regards,
Nikita


Re: [PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2020-12-16 Thread Craig Duncan
While making internal functions treat non-nullable types consistently with
userland is an absolute win,
I do wonder if it should be done simultaneously with changing some functions
to formally accept nulls.

I'm thinking back to all the pain caused when *count() *starting raising a
warning for null values.
We saw a lot of code that passed undeclared variables to *count()*
and I can imagine people writing similar code with something like *strlen()*


Re: [PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2020-12-02 Thread tyson andre
Hi Nikita,

> I've put up an RFC to make the handling of "null" arguments consistent
> between internal and user-defined functions:
> 
> https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
> 
> I started an informal discussion for this change during the 7.4 cycle
> already, but decided to postpone the change at the time.

Sounds like a good idea - available open source static analyzers are much 
better than they were when php 7.0.0 was released,
and php now has nullable types, union types and property types.

E.g. Phan already warns about passing null/nullable to internal functions as 
strictly as user-defined functions,
partly because I'd assumed internal functions would change in the future.
https://phan.github.io/demo/?code=%3C%3Fphp%0Afunction+test%28%3Fstring+%24str%29+%7B%0Areturn+strlen%28%24str%29+%2B+strlen%28null%29%3B%0A%7D
(10MB webassembly demo)

Regards,
Tyson
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2020-12-01 Thread Josh Bruce


> On Dec 1, 2020, at 8:57 AM, Nikita Popov  wrote:
> 
> I've put up an RFC to make the handling of "null" arguments consistent
> between internal and user-defined functions:
> 
> https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg 
> 
> 
> I started an informal discussion for this change during the 7.4 cycle
> already, but decided to postpone the change at the time.

For what it’s worth, you had me at more consistent (and constrained) use of 
“null”.

Cheers,
Josh

Re: [PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2020-12-01 Thread Larry Garfield
On Tue, Dec 1, 2020, at 8:57 AM, Nikita Popov wrote:
> Hi internals,
> 
> I've put up an RFC to make the handling of "null" arguments consistent
> between internal and user-defined functions:
> 
> https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
> 
> I started an informal discussion for this change during the 7.4 cycle
> already, but decided to postpone the change at the time.
> 
> Regards,
> Nikita

Seems well thought-out to me.  Endorse.

--Larry Garfield

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



Re: [PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2020-12-01 Thread Sebastian Bergmann

Am 01.12.2020 um 15:57 schrieb Nikita Popov:

I've put up an RFC to make the handling of "null" arguments consistent
between internal and user-defined functions:


Makes sense to me, +1.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php



[PHP-DEV] [RFC] Deprecate passing null to non-nullable arguments of internal functions

2020-12-01 Thread Nikita Popov
Hi internals,

I've put up an RFC to make the handling of "null" arguments consistent
between internal and user-defined functions:

https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

I started an informal discussion for this change during the 7.4 cycle
already, but decided to postpone the change at the time.

Regards,
Nikita