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

Argument 4 of mkdir cannot be null #10796

Closed
steal3rd opened this issue Mar 8, 2024 · 4 comments · Fixed by #10802
Closed

Argument 4 of mkdir cannot be null #10796

steal3rd opened this issue Mar 8, 2024 · 4 comments · Fixed by #10802

Comments

@steal3rd
Copy link

steal3rd commented Mar 8, 2024

Psalm is reporting the fourth argument of the mkdir() function cannot be null, but the function works as expected if used anyway.

The full message is:

Argument 4 of mkdir cannot be null, null value provided to parameter with type resource

And can be see with this example:

https://psalm.dev/r/6c64902528

mkdir("home/sample", 0755, true); // Works
mkdir("home/sample", 0755, true, null); // Also works

It's difficult to find examples of how this parameter would be used, but PHP does support passing a null for this argument. The docs describe it that way as well.

https://www.php.net/manual/en/function.mkdir

mkdir(
	string $directory,
	int $permissions = 0777,
	bool $recursive = false,
	?resource $context = null
): bool
Copy link

I found these snippets:

https://psalm.dev/r/6c64902528
<?php

mkdir("home/sample", 0755, true, null)
Psalm output (using commit 3600d51):

ERROR: ParseError - 3:39 - Syntax error, unexpected EOF on line 3

ERROR: NullArgument - 3:34 - Argument 4 of mkdir cannot be null, null value provided to parameter with type resource

@ging-dev
Copy link
Contributor

ging-dev commented Mar 8, 2024

Psalm is reporting the fourth argument of the mkdir() function cannot be null, but the function works as expected if used anyway.

The full message is:

Argument 4 of mkdir cannot be null, null value provided to parameter with type resource

And can be see with this example:

https://psalm.dev/r/6c64902528

mkdir("home/sample", 0755, true); // Works
mkdir("home/sample", 0755, true, null); // Also works

It's difficult to find examples of how this parameter would be used, but PHP does support passing a null for this argument. The docs describe it that way as well.

https://www.php.net/manual/en/function.mkdir

mkdir(
	string $directory,
	int $permissions = 0777,
	bool $recursive = false,
	?resource $context = null
): bool

You can fix callmap signature in this line: https://github.com/vimeo/psalm/blob/dca888c777aabd07aae4d2dc126cb90c5a432b90/dictionaries/CallMap.php#L6860

Copy link

I found these snippets:

https://psalm.dev/r/6c64902528
<?php

mkdir("home/sample", 0755, true, null)
Psalm output (using commit 3600d51):

ERROR: ParseError - 3:39 - Syntax error, unexpected EOF on line 3

ERROR: NullArgument - 3:34 - Argument 4 of mkdir cannot be null, null value provided to parameter with type resource

@weirdan
Copy link
Collaborator

weirdan commented Mar 9, 2024

Note that PHP versions before 7.3 did not accept null: https://3v4l.org/APVEI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants