Skip to content

Conversation

@Triplkrypl
Copy link

I found in crash way, that get_object_vars can return array with int key.

https://onlinephp.io/c/9a628

@staabm
Copy link
Contributor

staabm commented Nov 28, 2025

Can numeric keys only occur for objects without a class?

If so it might make sense to use a return type extension instead which can narrow the type depending on the context.

edit: and I think you should target PHPStan 2.1.x

@Triplkrypl
Copy link
Author

Can numeric keys only occur for objects without a class?

Not exactly classes extending \stdClass or has #[\AllowDynamicProperties] attribute.
Fore the classes is this code valid and before deprecation is code valid for every object:

$obj = new \stdClass();
$obj->{1} = 42;

If anyone want make dynamic return type detection, condition only for class is not enough.
For now in PHP 8 every object can have only numeric property, it is only deprecation error:
https://onlinephp.io/c/9704f

and I think you should target PHPStan 2.1.x

I am not sure if you support fixes for function interfaces in phpstan version 1.

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.

2 participants