Fix PHP numeric deserializer keys - #8012
Open
AayushP123 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the PHP writer to avoid PHPStan return-type inference failures for Parsable::getFieldDeserializers() when OpenAPI serialized property names are canonical numeric strings (e.g., "0", "500"), which PHP treats as integer array keys.
Changes:
- Detect canonical numeric serialized property names in generated PHP deserializers and emit an annotated local
$deserializersvariable before returning it. - Preserve existing direct
return [...]output for models without numeric serialized property names. - Add PHP writer test coverage for a numeric serialized property name case, and document the change in the changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs |
Adds canonical-numeric key detection and conditionally returns an annotated local deserializer array to satisfy static analysis. |
tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs |
Adds a regression test asserting the annotated $deserializers path is used for a "500" serialized name. |
CHANGELOG.md |
Notes the PHP static-analysis fix for numeric deserializer keys. |
AayushP123
force-pushed
the
agent/fix-7830-php-numeric-deserializer-keys
branch
from
August 1, 2026 09:10
db6d851 to
1ab0b04
Compare
AayushP123
marked this pull request as ready for review
August 2, 2026 16:33
Comment on lines
692
to
+693
| writer.WriteLines( | ||
| $"return {((extendsModelClass) ? $"array_merge(parent::{method.Name.ToFirstCharacterLowerCase()}(), [" : " [")}"); | ||
| $"{(hasNumericPropertyName ? "$deserializers =" : "return")} {((extendsModelClass) ? $"array_merge(parent::{method.Name.ToFirstCharacterLowerCase()}(), [" : " [")}"); |
Contributor
|
@AayushP123 Could you also remove the exclusion for this error in "config.json"? Lines 165 to 175 in b9e6126 |
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
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
Fixes #7830.
PHP converts canonical numeric string array keys such as
'0'and'500'to integers. As a result, PHPStan infers an integer-keyed array for generated deserializers even thoughParsable::getFieldDeserializers()returnsarray<string, callable>.Changes
Parsablecontract.Testing
dotnet test tests/Kiota.Builder.Tests/Kiota.Builder.Tests.csproj --filter FullyQualifiedName~Writers.Php.CodeMethodWriterTests --no-restoredotnet test tests/Kiota.Builder.Tests/Kiota.Builder.Tests.csproj --no-restoredotnet format kiota.slnx --include src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs tests/Kiota.Builder.Tests/Writers/Php/CodeMethodWriterTests.cs --no-restore --verify-no-changes