Skip to content

[sqlsrv] Use union return types matching the extension's behaviour - #59

Merged
jordikroon merged 1 commit into
php:mainfrom
officialasishkumar:fix/sqlsrv-return-types
Nov 28, 2026
Merged

jordikroon merged 1 commit into
php:mainfrom
officialasishkumar:fix/sqlsrv-return-types

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

Several sqlsrv function synopses declared a single return type (or mixed), even though the return values section and the extension itself also return false and/or null. For example, sqlsrv_fetch_array() was declared as returning array, but it returns null when there are no more rows and false on error.

I checked each function against source/sqlsrv in microsoft/msphpsql and updated the synopses to the types they actually return:

Function Before After
sqlsrv_fetch_array() array array|false|null
sqlsrv_fetch_object() mixed object|false|null
sqlsrv_errors() mixed array|false|null
sqlsrv_fetch(), sqlsrv_next_result() mixed bool|null
sqlsrv_send_stream_data() bool bool|null
sqlsrv_connect() resource resource|false
sqlsrv_prepare(), sqlsrv_query() mixed resource|false
sqlsrv_client_info(), sqlsrv_server_info() array array|false
sqlsrv_field_metadata() mixed array|false
sqlsrv_num_fields(), sqlsrv_num_rows() mixed int|false
sqlsrv_get_config() mixed int|bool

Three return values sections also didn't list every value the function can return, so I completed them:

  • sqlsrv_send_stream_data() returns null (not false) once all the data has been sent, and false on error.
  • sqlsrv_server_info() returns false on failure.
  • sqlsrv_errors() returns false when errorsOrWarnings is not a valid value.

sqlsrv_get_field() stays mixed, since it returns the field data, which can be of any type.

Fixes #28

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 jordikroon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for this PR. I have verified this with microsoft/msphpsql and it matches with the source.

@jordikroon
jordikroon merged commit 2478fcd into php:main Nov 28, 2026
2 checks passed
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.

sqlsrv_fetch_array(): array but can also return null and false

2 participants