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

Init properties with OpenApi\UNDEFINED is not a good solution #931

Closed
Tobion opened this issue Apr 18, 2021 · 3 comments
Closed

Init properties with OpenApi\UNDEFINED is not a good solution #931

Tobion opened this issue Apr 18, 2021 · 3 comments
Labels

Comments

@Tobion
Copy link
Contributor

Tobion commented Apr 18, 2021

All properties are currently initialized with the OpenApi\UNDEFINED constant (a string value). I know the reason for this is to distinguish null and undefined.
But this is pretty ugly as working with the code requires checking every property for this undefined constant before using it.
This also makes static analysers complain for every property access as the phpdoc type does not reflect this.
It will also be incompatible with PHP 7.4 property types.

But with property types we shouldn't need the undefined init anymore. Typed properties are un-initialized and swagger-php can use this to distinguish null and undefined.
Unfortunately switching all the properties to uninitialized is kind of a bc break as other code currently checks properties against the constant instead of checking if they are set (ussing isset). But I think it's the right way forward.

What do you think? Do you have plans in this regard?

@DerManoMann
Copy link
Collaborator

No real plans but PR #928 already reduces UNDEFINED to a single class const. I agree that the type conflicts that the const creates is not nice; we'll just have to wait until 7.4 is the lowest supported version ...

@DerManoMann
Copy link
Collaborator

Good news is that the PHP attribute contructors seem to work fine with typehints :)

@DerManoMann
Copy link
Collaborator

Closing due to inactivity.

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

No branches or pull requests

2 participants