Skip to content

Update ext/sockets parameter names #6276

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

Closed
wants to merge 4 commits into from
Closed

Conversation

nikic
Copy link
Member

@nikic nikic commented Oct 5, 2020

No description provided.

@@ -10,7 +10,7 @@ final class AddressInfo
{
}

function socket_select(?array &$read_fds, ?array &$write_fds, ?array &$except_fds, ?int $tv_sec, int $tv_usec = 0): int|false {}
function socket_select(?array &$read, ?array &$write, ?array &$except, ?int $seconds, int $microseconds = 0): int|false {}
Copy link
Member

Choose a reason for hiding this comment

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

ext/date uses $second (and $microseconds), so we should syncronize these. I'd naturally use $seconds too, but I have no idea about the best solution (e.g. $hours sounds bad).

Copy link
Member Author

@nikic nikic Oct 6, 2020

Choose a reason for hiding this comment

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

I believe the relevant difference between the ext/date usage and other usages is that ext/date uses $second in something like mktime($hour, $minute, $second, $day, $month, $year), where a point in time is assembled from components. In this case, using the singular makes sense. Outside ext/date, $seconds is generally used to describe a time interval for a timeout, in which case the plural makes sense. It's the difference between "at which second" and "how many seconds".

Copy link
Member

Choose a reason for hiding this comment

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

I digged into the Python manual for inspiration again, and found that they always use the plural form: https://docs.python.org/3/library/datetime.html#timedelta-objects So probably $hours is not that bad :)

Copy link
Member

Choose a reason for hiding this comment

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

It's the difference between "at which second" and "how many seconds".

Aha, I see now! I wouldn't have noticed this difference.

@@ -10,7 +10,7 @@ final class AddressInfo
{
}

function socket_select(?array &$read_fds, ?array &$write_fds, ?array &$except_fds, ?int $tv_sec, int $tv_usec = 0): int|false {}
function socket_select(?array &$read, ?array &$write, ?array &$except, ?int $seconds, int $microseconds = 0): int|false {}

function socket_create_listen(int $port, int $backlog = 128): Socket|false {}
Copy link
Member

Choose a reason for hiding this comment

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

I was about to suggest the usage of $max_connections instead of $backlog, but found out it's an stablished term. What a pity ^^


function socket_addrinfo_explain(AddressInfo $addr): array {}
function socket_addrinfo_explain(AddressInfo $address): array {}

#ifdef PHP_WIN32
function socket_wsaprotocol_info_export(Socket $socket, int $target_pid): string|false {}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
function socket_wsaprotocol_info_export(Socket $socket, int $target_pid): string|false {}
function socket_wsaprotocol_info_export(Socket $socket, int $target_process_id): string|false {}
Suggested change
function socket_wsaprotocol_info_export(Socket $socket, int $target_pid): string|false {}
function socket_wsaprotocol_info_export(Socket $socket, int $target_pid): string|false {}

/** @param string|null $buf */
function socket_recv(Socket $socket, &$buf, int $len, int $flags): int|false {}
/** @param string|null $data */
function socket_recv(Socket $socket, &$data, int $length, int $flags): int|false {}
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering before if our $length and $max_length usages are really consistent. E.g. the manual says here Up to len bytes will be fetched from remote host so it seems it could also be $max_length.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've been wondering about this as well. I think it might make sense to make all of these use just $length, unless they have some non-standard meaning (e.g. in the zlib case, where "max length" refers to a limit on the decoded payload size).

Copy link
Member

@kocsismate kocsismate Oct 6, 2020

Choose a reason for hiding this comment

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

I think it might make sense to make all of these use just $length

Yes, it's what I also thought about proposing before, but I wasn't sure if it's the preferable thing to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've done this now. Everything uses just $length now, apart from zlib uncompression:

ext/zlib/zlib.stub.php:function zlib_decode(string $data, int $max_length = 0): string|false {}
ext/zlib/zlib.stub.php:function gzinflate(string $data, int $max_length = 0): string|false {}
ext/zlib/zlib.stub.php:function gzdecode(string $data, int $max_length = 0): string|false {}
ext/zlib/zlib.stub.php:function gzuncompress(string $data, int $max_length = 0): string|false {}

@php-pulls php-pulls closed this in 79484b4 Oct 6, 2020
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.

2 participants