Re: Deprecated partially supported callables: should is_callable() throw a deprecation notice ?
| From: | Christian Schneider | Date: | Wed, 16 Mar 2022 08:57:04 +0000 |
| Subject: | Re: Deprecated partially supported callables: should is_callable() throw a deprecation notice ? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117344@lists.php.net to get a copy of this message | ||
Am 16.03.2022 um 06:52 schrieb Juliette Reinders Folmer <php-internals_nospam@adviesenzo.nl>:
> I've just been looking in detail at the Partially Supported Callables deprecation RFC:
> https://wiki.php.net/rfc/deprecate_partially_supported_callables
>
> The RFC explicitly excludes the
is_callable() function and the
> callable type from throwing deprecation notices.
>
>> The |is_callable()| function and |callable| type remain side-effect free and do not throw a
>> deprecation warning. They will continue to accept these callables until support is removed entirely.
>>
>
> While I can fully support this for the callable type, I wonder
> if the decision to not throw a deprecation on use in is_callable()
> is the right one (though I understand the desire to keep it side-effect free).
>
> Consider these code samples:
>
> function foo(callable $callback) {}
> foo('static::method');
>
> This function call not throwing a deprecation is not problematic as in PHP 9.0 the function
> will start throwing a TypeError.
My reaction to your last sentence is actually quite the opposite: This is a major problem because
code which was "just working" directly goes to a TypeError without a migration phase
warning about it. This is something I've repeatedly advocated against.
> if (is_callable('static::method')) {
> static::method();
> }
>
> The second code sample, however, is problematic, as in PHP 9.0, the behaviour of this code will
> be silently reversed for those callbacks which would previously result in
> is_callable() returning true, which makes this a potentially
> dangerous change without deprecation notice.
I agree with you here: Code which silently changes behavior is also a migration hassle.
- Chris