-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Fixes for PHP 8.1 #37101
[8.x] Fixes for PHP 8.1 #37101
Conversation
* @var string | ||
* @var ?string | ||
*/ | ||
protected $connection; | ||
protected $connection = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the default in the constructor, which is bypassed by mocks. The same goes for $prefix
.
} | ||
|
||
if (static::$connectionFailedOnceWithDefaultsSkip) { | ||
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__); | ||
|
||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
markTestSkipped()
has @psalm-return never-return
annotation. There are 48 occurrences of this method in Laravel tests and only those two are followed by a return.
@jrmajor thanks a bunch for these prs 👍 |
@jrmajor If there is an update with PHP 8.1 that will require this pull request, I don't fully understand what this update is about? |
@selcukcukur I'm not sure I've understood your question. PHP 8.1 will be released on November 25, but early dev builds are available for testing, and we want Laravel to be ready for it when it lands. This PR fixes passing null to non-nullable arguments of internal functions, which was deprecated in this RFC. You can see a list of other implemented proposals there. |
I got it, I looked at this document now. So why do we translate an empty string? Wouldn't it make more sense to have these parameters do the string conversion? Sample : protected $foo;
public function bar(string $foo = null)
{
return (string) $foo;
} or protected $foo;
public function bar($foo = null)
{
return $foo ? (string) $foo : $foo;
} or protected $foo;
public function bar($foo = null)
{
if(is_null($foo) {
return (string) $foo;
}
} I still don't understand why we had to make the parameter an empty string. The transformations I have shown above can be easily applied where necessary. Isn't this a better solution than the examples I've shown, am I wrong? |
Also, what's the aim of having
What parameter? |
*/ | ||
protected $connection; | ||
protected $connection = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it will throw a type exception when it takes a "null" value, we can fix it by converting it to a string. I am saying this from the following point of view. It doesn't seem nice to me to define default values for parameters in the class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Briefly, isn't it a good solution to convert a "null" value to a string instead of defining it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem nice to me to define default values for parameters in the class.
It has already had the default value and it was defined in the constructor. Using mocks, however, bypasses the constructor and this property isn't set to its default. I've written that already in this comment.
Seems pretty nice to me, that's how default properties are meant to be used. It just has been unnecessary, as it was set in the constructor anyway (except for when this class was mocked, which nobody noticed).
* fix PHP 8.1 deprecations (broadcasting) * fix PHP 8.1 deprecations (cache) * remove returns after never-return method call * fix PHP 8.1 deprecations (bus) * fix PHP 8.1 deprecations (database) * fix PHP 8.1 deprecations (validation) * use strict comparison * fix PHP 8.1 deprecations (mail) * fix PHP 8.1 deprecations (routing)
Fixes passing null to non-nullable parameters.