oooas icon indicating copy to clipboard operation
oooas copied to clipboard

Add return typehints to Extensions ArrayAccess

Open judgej opened this issue 2 years ago • 10 comments

Fix for https://github.com/goldspecdigital/oooas/issues/52

judgej avatar Jan 06 '22 19:01 judgej

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

judgej avatar Jan 06 '22 19:01 judgej

@matthew-inamdar Can you please merge this?

lotyp avatar Mar 02 '22 15:03 lotyp

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

PrinsFrank avatar Mar 21 '22 13:03 PrinsFrank

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?

matthew-inamdar avatar Mar 21 '22 13:03 matthew-inamdar

@matthew-inamdar Yes, that would suffice!

PrinsFrank avatar Mar 21 '22 13:03 PrinsFrank

@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.

PrinsFrank avatar Mar 21 '22 20:03 PrinsFrank

@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?

TheodoorP avatar Mar 22 '22 22:03 TheodoorP

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

lotyp avatar May 20 '22 09:05 lotyp

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?

PrinsFrank avatar Jun 30 '22 14:06 PrinsFrank

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: https://github.com/adrienbrault/oooas/commit/f24ceb1d0d5d9d1e2547c4b8797c6514220b8f69

adrienbrault avatar Feb 15 '24 09:02 adrienbrault