Skip to content
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

Fix php81 deprecated warnings #74

Closed
wants to merge 2 commits into from

Conversation

pbojan
Copy link

@pbojan pbojan commented Jan 31, 2022

🔀 Pull Request

What does this PR do?

Fix deprecated warnings for PHP 8.1:

Deprecated: Return type of Flow\JSONPath\JSONPath::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Exception:
ErrorException: Deprecated: Return type of Flow\JSONPath\JSONPath::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/foe/libs/external/softcreatr/jsonpath/src/JSONPath.php:271

Test Plan

No automated test plan only manual testing done.

Related PRs and Issues

No related PRs or Issues

@SoftCreatR
Copy link
Owner

SoftCreatR commented Jan 31, 2022

Thank you. However, this will be a breaking change, since the mixed keyword doesn't exist in older PHP versions.

So to get rid of these notices, way more work is required (e.g. publish a new tag >= 0.8), PHP unit updates, etc.

@pbojan
Copy link
Author

pbojan commented Jan 31, 2022

That is very true. Any plans from your side to migrate to at least PHP 8.0? I could potentially help out but I don't know how much work that would be as I am not aware of all the side-effects that could create.

@SoftCreatR
Copy link
Owner

PHP 8.0+ is officially supported and covered by our automatic tests (see https://github.com/SoftCreatR/JSONPath/blob/main/.github/workflows/Test.yml#L24).

However, if there's any need, I'll release a new version for sure.

@andrew-demb
Copy link

How about just adding #[\ReturnTypeWillChange] attribute?

@SoftCreatR
Copy link
Owner

That's the current plan.

@SoftCreatR
Copy link
Owner

That's also a breaking change, because it doesn't work with older PHP versions.

@pbojan
Copy link
Author

pbojan commented Jan 31, 2022

Should I update the PR to remove the mixed and replace it with the Attribute then?

@SoftCreatR
Copy link
Owner

No. A new version (for PHP 8.0+) is required here.

@pbojan
Copy link
Author

pbojan commented Jan 31, 2022

Actually I think this works because for previous PHP versions attributes are regarded as comments:

PHP versions prior to 8.0 parses the attribute syntax as a code comment, and does not cause any syntax errors. Adding #[\ReturnTypeWillChange] attribute to a class method does not cause any issues, but omits the deprecation notice in PHP 8.1.

https://php.watch/versions/8.1/ReturnTypeWillChange

@SoftCreatR
Copy link
Owner

Yeah, my bad. I forgot to put that on a separate line, so all tests failed locally :)

But I'm already working on updates.

@SoftCreatR
Copy link
Owner

Resolved via 37f949d

@SoftCreatR SoftCreatR closed this Jan 31, 2022
@pbojan pbojan deleted the fix-php81-deprecated-warnings branch January 31, 2022 15:01
@pbojan
Copy link
Author

pbojan commented Jan 31, 2022

@SoftCreatR thank you for the quick fix!

@SoftCreatR
Copy link
Owner

Please let me know, if the provided solution works for you.

@gigimaor
Copy link

gigimaor commented Mar 7, 2023

Hello
Continuing to the above, I have the same issue, but no solution is present in the code.

Error message Deprecated function: Return type of Flow\JSONPath\JSONPath::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in include() (line 29 of /builds/web-team/ua-arop/vendor/softcreatr/jsonpath/src/JSONPath.php).

This new attribute that supports php:^81 is required #[\ReturnTypeWillChange] or fixing the compatibility issue described in the error.

Please advise.

@SoftCreatR
Copy link
Owner

Are you using the latest version 0.8.2?

@gigimaor
Copy link

gigimaor commented Mar 8, 2023

I update the version, and the solution presents itself

@SoftCreatR
Copy link
Owner

Means?

@gigimaor
Copy link

gigimaor commented Mar 8, 2023

Updating to version 0.8.2 has fixed the issue. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants