Skip to content

Treat array_column() string keys as property reads#362

Merged
janedbal merged 3 commits into
masterfrom
jn-array-column-property-reads
May 18, 2026
Merged

Treat array_column() string keys as property reads#362
janedbal merged 3 commits into
masterfrom
jn-array-column-property-reads

Conversation

@janedbal
Copy link
Copy Markdown
Member

@janedbal janedbal commented May 15, 2026

Summary

  • Mark the 2nd (column_key) and 3rd (index_key) string arguments of array_column() as property READs on the iterable value type of the 1st arg, when that element type is definitely an object.
  • Mirrors PHP semantics: only string keys map to properties (ints are array offsets), and only object element types trigger property access — array/mixed/union-with-array element types fall through to avoid false negatives elsewhere.

Closes #361

janedbal added 2 commits May 15, 2026 14:40
Closes #361

Co-Authored-By: Claude Code
mixed / object|array could be an array at runtime, in which case
array_column reads array keys, not properties — don't poison the
codebase by wildcard-marking every same-named property as used.

Co-Authored-By: Claude Code
@janedbal janedbal marked this pull request as ready for review May 18, 2026 07:01
@janedbal janedbal merged commit 30d1d4a into master May 18, 2026
32 checks passed
@janedbal janedbal deleted the jn-array-column-property-reads branch May 18, 2026 07:45
*
* @param array<Arg> $args
*/
private function registerArrayColumnPropertyReads(
Copy link
Copy Markdown
Contributor

@staabm staabm May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstan internally already tracks property reads and writes.
I wonder why you need such function specific custom implementations in this package

see e.g. ClassPropertiesNode

Copy link
Copy Markdown
Member Author

@janedbal janedbal May 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

property reads and writes in ClassPropertiesNode are usable only for private props really

@ruudk
Copy link
Copy Markdown
Contributor

ruudk commented May 18, 2026

@janedbal would you mind tagging a new release?

@janedbal
Copy link
Copy Markdown
Member Author

Tagged, 1.1.3

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.

array_column() not recognised as property usage

3 participants