Repository navigation
[sqlsrv] Use union return types matching the extension's behaviour - #59
Merged
Merged
Conversation
Several sqlsrv function synopses declared a single return type (or mixed) although the return values section, and the extension itself, document additional false and/or null returns. For instance sqlsrv_fetch_array() was declared as returning array while it returns null when there are no more rows and false on error. Update the synopses to the union types actually returned by the extension (checked against microsoft/msphpsql source/sqlsrv): - sqlsrv_fetch_array(): array|false|null - sqlsrv_fetch_object(): object|false|null - sqlsrv_errors(): array|false|null - sqlsrv_fetch(), sqlsrv_next_result(), sqlsrv_send_stream_data(): bool|null - sqlsrv_connect(), sqlsrv_prepare(), sqlsrv_query(): resource|false - sqlsrv_client_info(), sqlsrv_server_info(), sqlsrv_field_metadata(): array|false - sqlsrv_num_fields(), sqlsrv_num_rows(): int|false - sqlsrv_get_config(): int|bool Also complete the return values sections that did not mention every returned value: sqlsrv_send_stream_data() returns null (not false) once all data has been sent and false on error, sqlsrv_server_info() returns false on failure, and sqlsrv_errors() returns false for an invalid errorsOrWarnings value. Fixes php#28
jordikroon
approved these changes
Nov 28, 2026
jordikroon
left a comment
Member
There was a problem hiding this comment.
Thank you for this PR. I have verified this with microsoft/msphpsql and it matches with the source.
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.
Several
sqlsrvfunction synopses declared a single return type (ormixed), even though the return values section and the extension itself also returnfalseand/ornull. For example,sqlsrv_fetch_array()was declared as returningarray, but it returnsnullwhen there are no more rows andfalseon error.I checked each function against
source/sqlsrvin microsoft/msphpsql and updated the synopses to the types they actually return:sqlsrv_fetch_array()arrayarray|false|nullsqlsrv_fetch_object()mixedobject|false|nullsqlsrv_errors()mixedarray|false|nullsqlsrv_fetch(),sqlsrv_next_result()mixedbool|nullsqlsrv_send_stream_data()boolbool|nullsqlsrv_connect()resourceresource|falsesqlsrv_prepare(),sqlsrv_query()mixedresource|falsesqlsrv_client_info(),sqlsrv_server_info()arrayarray|falsesqlsrv_field_metadata()mixedarray|falsesqlsrv_num_fields(),sqlsrv_num_rows()mixedint|falsesqlsrv_get_config()mixedint|boolThree return values sections also didn't list every value the function can return, so I completed them:
sqlsrv_send_stream_data()returnsnull(notfalse) once all the data has been sent, andfalseon error.sqlsrv_server_info()returnsfalseon failure.sqlsrv_errors()returnsfalsewhenerrorsOrWarningsis not a valid value.sqlsrv_get_field()staysmixed, since it returns the field data, which can be of any type.Fixes #28