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

Object instance's string constants cannot be used as array keys with other hard-coded strings #5096

Closed
davidbyoung opened this issue Jan 24, 2021 · 3 comments · Fixed by #6321

Comments

@davidbyoung
Copy link

As in my example, using the class constant works, but using the constant directly from an instance does not work.

https://psalm.dev/r/496e0e40cc

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/496e0e40cc
<?php

class Foo
{
    public const BAR = 'bar';
}

$foo = new Foo();
$workingArray = ['foo' => 'bar', Foo::BAR => 'baz'];
$brokenArray = ['foo' => 'bar', $foo::BAR => 'baz'];
Psalm output (using commit b618313):

INFO: MixedArrayOffset - 10:16 - Cannot create mixed offset – expecting array-key

@orklah
Copy link
Collaborator

orklah commented Jan 24, 2021

Simplified: https://psalm.dev/r/d3471853a2

@psalm-github-bot
Copy link

I found these snippets:

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

class Foo
{
    public const BAR = 'bar';
}

$foo = new Foo();
/** @psalm-trace $_trace */
$_trace = $foo::BAR;
Psalm output (using commit b618313):

INFO: Trace - 10:1 - $_trace: mixed

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