Skip to content

Validate query parameters and reject non-scalars #211

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

Merged
merged 3 commits into from
Jul 15, 2025

Conversation

clue
Copy link
Contributor

@clue clue commented Jul 15, 2025

This changeset ensures we properly validate any query parameters and reject unsupported non-scalars such as objects/arrays/resources. This should be in line with the existing design and should not affect any existing code using scalar or null values.

// old (still supported)
$mysql->query('SELECT * FROM user WHERE name = ? and age > ?', ['Alice', 42]);

// now throws an InvalidArgumentException for invalid params
$mysql->query('SELECT ?', [new stdClass()]);

Most notably, this fixes an old bug that would invalidate the entire connection object if an unexpected value is passed as discussed in #167. With these changes applied, it will now properly reject any invalid values, leaving the connection in a valid state for any following queries. The affected code comes with updated tests that have 100% code coverage.

Additionally, it adds some stricter types to the public API that makes it easier to detect this problem for any static analysis tools such as PHPStan or your favorite IDE.

On top of this, this is done in preparation for named query params as discussed in #41. Among others, this will change the list type to an array type again. I'll file a follow-up PR once this one is in.

If you want to support this project, please consider sponsoring @reactphp – sponsorships really do make a difference ❤️

Builds on top of #210, #186, #40, clue/reactphp-redis#171, and others
Resolves / closes #167
Refs #41

@clue clue added this to the v0.7.0 milestone Jul 15, 2025
@clue clue requested review from WyriHaximus and PaulRotmann July 15, 2025 09:54
Copy link
Contributor

@PaulRotmann PaulRotmann left a comment

Choose a reason for hiding this comment

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

👍

@WyriHaximus WyriHaximus merged commit b4c83f1 into friends-of-reactphp:0.7.x Jul 15, 2025
17 checks passed
@clue clue deleted the scalar-params branch July 15, 2025 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not send more queries after 'Not supportted value type' exception
3 participants