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

get_object_vars assumes object does not have properties #7392

Closed
jsiefer opened this issue Jan 14, 2022 · 2 comments · Fixed by #7401
Closed

get_object_vars assumes object does not have properties #7392

jsiefer opened this issue Jan 14, 2022 · 2 comments · Fixed by #7401
Labels

Comments

@jsiefer
Copy link

jsiefer commented Jan 14, 2022

Example: https://psalm.dev/r/fe5ff75f6a

Hi, the statement would be correct for class A and if it was final, but it should take into account that a class could be extended, or?

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/fe5ff75f6a
<?php

class A { 
}
class B {
    public int $a = 1;
}

function writeDictionary(A $dictionary): void
{
	$values = get_object_vars($dictionary);
	ksort($values, SORT_STRING);
}
Psalm output (using commit 0ded59d):

ERROR: RedundantFunctionCall - 12:2 - The call to ksort is unnecessary, array<never, never> is already a list

@orklah orklah added the bug label Jan 14, 2022
@orklah
Copy link
Collaborator

orklah commented Jan 14, 2022

indeed, Psalm should not assume a child of the appearing object won't have new properties, unless the class is final.

This is handled here:

(and also two more lines like it in the same file)

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