-
Notifications
You must be signed in to change notification settings - Fork 2
PHP8 Features #35
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
PHP8 Features #35
Conversation
| * @return int|null | ||
| */ | ||
| public static function findUserId($model): ?int | ||
| public static function findUserId(Model|null $model): ?int |
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.
What about nullable type hint?
| public static function findUserId(Model|null $model): ?int | |
| public static function findUserId(?Model $model): ?int |
| //-------------------------------------------------------------------------------------------------------------- | ||
|
|
||
| protected function setIpAddressAttribute($value) | ||
| protected function setIpAddressAttribute(string|null $value): void |
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.
Nullable type hint here too?
| protected function setIpAddressAttribute(string|null $value): void | |
| protected function setIpAddressAttribute(?string $value): void |
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.
Is this just sugar? Or is anything different from the two? Just curious as ?|string is not a valid docblock, but string|null is.
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's syntactic sugar
A single base type declaration can be marked nullable by prefixing the type with a question mark (?). Thus ?T and T|null are identical.
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.
Okay, so it seems it works in userland, just docblock parsing doesn't work yet for those - https://github.com/laravel/framework/pull/45677/files
| ActivityType::PASSWORD_CHANGE => trans('logger::enums.activity_type_password_change'), | ||
| ActivityType::GET_DATA => trans('logger::enums.activity_type_get_data'), | ||
| ActivityType::MODIFY_DATA => trans('logger::enums.activity_type_modify_data'), | ||
| default => throw new \Exception('Unknown enum type: ' . $this->type), |
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.
Could we simplify the namespace?
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.
I'll bring up a new PR to handle this and the nullable typehints
Logger