-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[PHP] Add declareStrictTypes option to AbstractPhpCodegen to generate declare(strict_types=1); #21179
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
Open
Gosling-dude
wants to merge
9
commits into
OpenAPITools:master
Choose a base branch
from
Gosling-dude:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…n AbstractPhpCodegen.java
…es=1); after <?php if declareStrictTypes is true
…es=1); after <?php if declareStrictTypes is true
…es=1); after <?php if declareStrictTypes is true
…es=1); after <?php if declareStrictTypes is true
…es=1); after <?php if declareStrictTypes is true
…es=1); after <?php if declareStrictTypes is true
wing328
reviewed
Apr 30, 2025
@@ -1,4 +1,6 @@ | |||
<?php | |||
{{#declareStrictTypes}}declare(strict_types=1);{{/declareStrictTypes}} |
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.
better do in the following way
{{#declareStrictTypes}}
declare(strict_types=1);
{{/declareStrictTypes}}
to avoid blank lines
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.
Sure, I'll do it.
wing328
reviewed
Apr 30, 2025
...s/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPhpCodegen.java
Show resolved
Hide resolved
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces support for a new generator option: declareStrictTypes for PHP code generation.
When enabled via
--additional-properties=declareStrictTypes=true
, the generated PHP files will start with:This enforces strict typing in the generated PHP client code, promoting best practices for modern PHP development.
Affected Files
Codegen Core:
AbstractPhpCodegen.java
→ Added support for the declareStrictTypes property and updated the help message.
PHP Template Files:
Located in
modules/openapi-generator/src/main/resources/php/
All updated to conditionally include:
{{#declareStrictTypes}}declare(strict_types=1);{{/declareStrictTypes}}
Usage Example
To generate PHP code with declare(strict_types=1); included at the top of the files, run:
Then check any generated file (e.g.,
ApiClient.php
) for:Fixes: #12771
Thank you for reviewing this contribution! 🙏