-
Notifications
You must be signed in to change notification settings - Fork 937
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 deprecated error in PHP 8.1/8.2 #1474
Conversation
Could you please explain how you got these warnings? Just running the tests on PHP 8.1 does not show any warnings for me at all. Also, I'd rather we fix the cause of the warning instead of just allowing dynamic properties if possible. |
I did just normal PHP 8.1
PHP 8.2
|
The Context class assumes dynamic properties by design, and the current master branch also has a I think this is not an error suppression, but a design declaration. |
Sorry, missed that this on the 2.x branch... I shouldn't try handling issues/PRs on my phone, I suppose... |
src/Annotations/Get.php
Outdated
@@ -9,6 +9,7 @@ | |||
/** | |||
* @Annotation | |||
*/ | |||
#[\AllowDynamicProperties] |
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 seems unrelated to the warnings documented?
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.
Without AllowDynamicProperties
attribute, This code causes a deprecate error. I thought I did not need this assignment ($this->$property = $value;
), but I gave the attribute to minimize the changes for the behavior unchanged at all.
If I can get rid of this code, I don't need the AllowDynamicProperties
attribute. (Is this unexpected property?) What should I do?
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.
Interesting. I have to admit that seem not to be able to reproduce the warnings; that would make everything a bit easier...
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 am also confused. I suspect my environment and have had others try, but the error is still there. (I would expect the error to occur since the code is dealing with a dynamic propertyn in PHP 8.1.) However, the GH action I performed in another PR did not reproduce the deprecated error...
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 think you have custom error logging settings. I would have thought this should be default for phpunit 🤷
php -d error_reporting=-1 ./bin/phpunit
... on 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.
Its this test: https://github.com/zircote/swagger-php/blob/2.x/tests/AbstractAnnotationTest.php#L19
Doesn't exist on master any more, otherwise we'd see the same there...
Not quite sure what to do - technically we should probably change the code to throw an exception rather than logging and moving on; just not sure if that is too much of a BC break.
OTOH, this is the first time I've seen this issue, so I would suspect there are not a lot of cases of this happeing out in the wild. On top of that thoses properties are either ignored during serialization or bu any other OpenAPI tools.
I would lean towards not allowing invalid specs to be created, so throwing an exception might be the way forward.
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 agree with you that it is correct to throw an exception as you think. But in any case, is there any need to set invalid properties? (I pushed a new commit)
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 remove this again? When not setting the property this should not be needed.
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.
One more text change and I think this is good to go.
Co-authored-by: Martin Rademacher <[email protected]>
Did you look at the PR #1476 ? I actually changed field to property, but more importantly there is a test to update too (that expects this particular message) |
This reverts commit 4650139.
I think there was some misunderstanding. The change to not set the property was fine. Only thing to change was that in my PR i also slightly changed the log message.... |
src/Annotations/Get.php
Outdated
@@ -9,6 +9,7 @@ | |||
/** | |||
* @Annotation | |||
*/ | |||
#[\AllowDynamicProperties] |
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 remove this again? When not setting the property this should not be needed.
Co-authored-by: Martin Rademacher <[email protected]>
This reverts commit 5384875.
Thanks for your patience @koriym |
This PR fixes two deprecated errors in PHP 8.1/8.2.
PHP Deprecated: Creation of dynamic property Swagger\Context::{$prop} is deprecated in swagger-php/src/Context.php on line 53
Deprecated: strcasecmp(): Passing null to parameter #1 ($string1) of type string is deprecated in swagger-php/src/Context.php on line 288
No more errors when doing
composer test
in PHP 8.1/8.2.Fixes #1455