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

False positive when passing null to socket_select #6318

Closed
Forceu opened this issue Aug 16, 2021 · 3 comments · Fixed by #6320
Closed

False positive when passing null to socket_select #6318

Forceu opened this issue Aug 16, 2021 · 3 comments · Fixed by #6320

Comments

@Forceu
Copy link
Contributor

Forceu commented Aug 16, 2021

<?php

$null = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$clients = array($socket);
socket_select($clients, $null, $null, $null, 0);

results in ERROR: NullArgument - 6:39 - Argument 4 of socket_select cannot be null, null value provided to parameter with type int

However the expected input is ?int and a null variable can be passed.

socket_select(
    ?array &$read,
    ?array &$write,
    ?array &$except,
    ?int $seconds,
    int $microseconds = 0
): int|false

https://www.php.net/manual/en/function.socket-select.php

https://psalm.dev/r/28b3494123

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/28b3494123
<?php

$null = null;
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$clients = array($socket);
socket_select($clients, $null, $null, $null, 0);
Psalm output (using commit 2e7763c):

ERROR: NullArgument - 6:39 - Argument 4 of socket_select cannot be null, null value provided to parameter with type int

@orklah
Copy link
Collaborator

orklah commented Aug 16, 2021

I can't execute it on 3v4l.org.

Do you mind checking on your php install that socket_select with a null argument does not trigger a TypeError when declare(strict_types=1); is on top of the file?

If it doesn't, great! Functions are declared in those files: https://github.com/vimeo/psalm/tree/master/dictionaries you should be able to update them accordingly

Forceu added a commit to Forceu/psalm that referenced this issue Aug 16, 2021
@Forceu
Copy link
Contributor Author

Forceu commented Aug 16, 2021

Thanks, it was indeed a bug within the dictionary. I created a pull request with the fix.

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 a pull request may close this issue.

2 participants