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

[mysql] Add stubs for mysqli, mysqli_result and mysqli_stmt classes #9547

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions stubs/extensions/mysqli.phpstub
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
<?php

class mysqli
{
/**
* @var int<-1, max>|numeric-string
*/
public int|string $affected_rows;
}

/**
* @template TValue
*
* @template-implements Traversable<int, TValue>
*/
class mysqli_result implements Traversable
{
/**
* @var int<0, max>|numeric-string
*/
public int|string $num_rows;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this to account for the limited int range on 32-bit platforms? While the 64-bit integer range is still limited, it's large enough to ignore possible overflow, in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know if in practice the limit from PHP_MAX_INT in 64-bit platforms (9223372036854775807) can be reached, but docs don't make any distinction in this matter:

If the number of affected rows is greater than maximum PHP int value, the number of affected rows will be returned as a string value.


/**
* @psalm-taint-sink callable $class
*
Expand All @@ -18,6 +31,44 @@ class mysqli_result implements Traversable
function fetch_object(string $class = stdClass::class, array $constructor_args = []): object|false|null {}
}

class mysqli_stmt
{
/**
* @var int<-1, max>|numeric-string
*/
public int|string $affected_rows;

public int $errno;

/**
* @var list<array{errno: int, sqlstate: string, error: string}>
*/
public $error_list;

public string $error;

/**
* @var 0|positive-int
*/
public int $field_count;

public int|string $insert_id;

/**
* @var int<0,max>|numeric-string
*/
public int|string $num_rows;

/**
* @var 0|positive-int
*/
public int $param_count;

/**
* @var non-empty-string
*/
public string $sqlstate;
}

/**
* @psalm-taint-sink callable $class
Expand Down