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

#8575 More strict signature for implode function #8595

Closed
wants to merge 1 commit into from

Conversation

SLaVeZ
Copy link

@SLaVeZ SLaVeZ commented Oct 17, 2022

Fix for issue #8575

@orklah
Copy link
Collaborator

orklah commented Oct 17, 2022

Thanks for trying to fix the issue :) Unfortunately, this is not correct.

Stringable is a symbol that was added on PHP 8. I'm not exactly sure how Psalm would react exactly on lower versions (most probably allow a Stringable class that would exist in user code or possibly crash outright) but it can't be good.

There is a stringable-object pseudo-type that is translated into an object that happens to have a __toString method in Psalm. It would be more correct in this situation but Psalm doesn't seem to enforce it: https://psalm.dev/r/8233ca5c0a

This is a bug that should be fixed first.

Also, the actual fix should be located in

function implode($separator, array $array = []) : string {}
instead of callmaps. When a stub is present, it overrides the callmap

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/8233ca5c0a
<?php

 implode2([new stdClass]);

/**
 * @param array<stringable-object> $separator
 */
function implode2($separator) : void {}
Psalm output (using commit 212281d):

INFO: UnusedParam - 8:19 - Param $separator is never referenced in this method

@weirdan
Copy link
Collaborator

weirdan commented Nov 9, 2022

This is fixed in #8688

@weirdan weirdan closed this Nov 9, 2022
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.

None yet

4 participants