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 type when using \PDO::FETCH_OBJ on iteration #751

Merged
merged 3 commits into from
Mar 5, 2025
Merged

Fix type when using \PDO::FETCH_OBJ on iteration #751

merged 3 commits into from
Mar 5, 2025

Conversation

staabm
Copy link
Owner

@staabm staabm commented Mar 5, 2025

closes #748

@@ -32,7 +32,7 @@ public function supportedFetchTypes(PDO $pdo)

$stmt = $pdo->query('SELECT email, adaid FROM ada', PDO::FETCH_OBJ);
foreach ($stmt as $row) {
assertType('array<int, stdClass>', $row);
assertType('object{email: string, adaid: int<-32768, 32767>}&stdClass', $row);
Copy link
Owner Author

@staabm staabm Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AllenJB does this look better/correct for you?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks! 👍

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AllenJB could you please fill another issue with your feature request regarding "how can I put a type onto a result-object" and your concrete use-case/example?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you're referring to phpstan/phpstan#9120

Did you just want me to repost that as a request on the phpstan-dba project? Or is there some information that's missing from there?

Did you see my latest comment with the reproducer repo I set up (which I've just updated for these changes)? And the related request for help I linked to on the phpstan project discussions? (Not sure how much the last will help you - it's just my current line of thinking on how to implement something that solves fetch mode handling well-enough to get back to at least what I had with the PDOStatement stub override under PHPStan 1)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, lets discuss in the already open discussion

@staabm staabm merged commit 813afaa into main Mar 5, 2025
26 checks passed
@staabm staabm deleted the pdo-obj branch March 5, 2025 14:16
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.

Wrong type when using \PDO::FETCH_OBJ (on iteration)
2 participants