Skip to content

Add return typehints to Extensions ArrayAccess#53

Open
judgej wants to merge 1 commit into
goldspecdigital:masterfrom
consilience:master
Open

Add return typehints to Extensions ArrayAccess#53
judgej wants to merge 1 commit into
goldspecdigital:masterfrom
consilience:master

Conversation

@judgej
Copy link
Copy Markdown

@judgej judgej commented Jan 6, 2022

Fix for #52

@judgej
Copy link
Copy Markdown
Author

judgej commented Jan 6, 2022

This package works find on PHP 8.0 but fails on PHP 8.1 without the return typehints for ArrayAccess.

We are using it as a depencency of vyuldashev/laravel-openapi

@lotyp
Copy link
Copy Markdown

lotyp commented Mar 2, 2022

@matthew-inamdar Can you please merge this?

@PrinsFrank
Copy link
Copy Markdown
Contributor

@matthew-inamdar This fix allows us to use the package, can you please merge this?

@matthew-inamdar
Copy link
Copy Markdown
Member

Sorry for the delay - I've been struggling for time recently.

These type hints will be a breaking change for currently supported PHP versions.

If we added the #[\ReturnTypeWillChange] attribute, would that suffice?

@PrinsFrank
Copy link
Copy Markdown
Contributor

PrinsFrank commented Mar 21, 2022

@matthew-inamdar Yes, that would suffice!

@PrinsFrank
Copy link
Copy Markdown
Contributor

@matthew-inamdar Thinking about my previous comment, adding a ReturnTypeWillChange attribute will be a bigger change than adding return type as it will drop support for any PHP version below 8.1. What exactly are you worried about regarding breaking changes with return types? The interface in PHP already has the return types specified, so it should not be really any issue.

Copy link
Copy Markdown
Contributor

@PrinsFrank PrinsFrank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe PHP 8.0 and 8.1 can also be added to the PHP matrix in .github/workflows/tests.yml on line 16?

@TheodoorP
Copy link
Copy Markdown

@matthew-inamdar Thinking about my previous comment, adding a ReturnTypeWillChange attribute will be a bigger change than adding return type as it will drop support for any PHP version below 8.1. What exactly are you worried about regarding breaking changes with return types? The interface in PHP already has the return types specified, so it should not be really any issue.

This won't be an issue due to the way attributes were designed in PHP. The attribute will work fine in php8.0 as no instance is actually created for it. As for any PHP version before PHP 8, the # prefix for attributes will be seen as comments by the engine, so the lines will just be skipped :)

TL;DR using #[\ReturnTypeWillChange] will not be a breaking change.

@matthew-inamdar if you would like, I could open a new PR with the ReturnTypeWillChange attribute and one that adds PHP 8.0 and 8.1 to the test matrix?

@lotyp
Copy link
Copy Markdown

lotyp commented May 20, 2022

@matthew-inamdar would be great to get your accept 🤓

@PrinsFrank
Copy link
Copy Markdown
Contributor

This PR is now obsolete as #55 as discussed above has been merged and released in 2.9.0. @judgej or @matthew-inamdar this PR can be closed then, right?

@adrienbrault
Copy link
Copy Markdown

Hey, this is still needed.

On v2.10.0 I was getting:

09:34:58 INFO      [deprecation] User Deprecated: Method "ArrayAccess::offsetSet()" might add "void" as a native return type declaration in the future. Do the same in implementation "GoldSpecDigital\ObjectOrientedOAS\Utilities\Extensions" now to avoid errors or add an explicit @return annotation to suppress this message. ["exception" => ErrorException { …}]
09:34:58 INFO      [deprecation] User Deprecated: Method "ArrayAccess::offsetUnset()" might add "void" as a native return type declaration in the future. Do the same in implementation "GoldSpecDigital\ObjectOrientedOAS\Utilities\Extensions" now to avoid errors or add an explicit @return annotation to suppress this message. ["exception" => ErrorException { …}]

This MR fixes the deprecation. Thank you!

Rebase: adrienbrault@f24ceb1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants