Okay, after posting an edit with the deep-assoc-completion link I figured out how to do this. This does what I wanted.

   foreach ($data->display_items as $line_item) {
      /** @var $metadata = CheckoutSessionLineItemMetadata::ARRAY_SHAPE */
      $metadata = $line_item->metadata;
    }
Answer from Matthew Weiner on Stack Overflow
🌐
JetBrains
blog.jetbrains.com › phpstorm › 2020 › 10 › phpstorm-2020-3-eap-4
PhpStorm 2020.3 EAP #4: Custom PHP 8 Attributes | The PhpStorm Blog
June 15, 2021 - Starting from PhpStorm 2020.3, it will be possible to define the structure of such arrays with an #[ArrayShape].
Discussions

I love php array shapes!
Hey, at least you got shapes! At work I'm having a hard time trying to convince people to stop declaring public function createSomething(array $data) methods. What's inside $data? Only Satan knows. More on reddit.com
🌐 r/programminghorror
28
94
November 20, 2023
PhpStorm 2020.3 will come with several PHP 8 attributes: #[ArrayShape], #[ExpectedValues], #[NoReturn], #[Pure], #[Deprecated], #[Immutable]
The attribute wars, begun, they have. More on reddit.com
🌐 r/PHP
61
114
October 26, 2020
Using PhpStorm Php 8 attributes
Psalm apparently added support for these . There was already equivalent functionality available via Psalm's own annotations so it sounds like it was just a case of mapping them to their PhpStorm equivalents. Psalm has also added similar attributes via a package, and as someone who uses Psalm and not PhpStorm that's obviously a more attractive option for me. Also, it has the advantage it can run in a CI environment. I'm also inclined to agree with the creator of Psalm that for ArrayShape the docblock version supported by Psalm is more succinct. More on reddit.com
🌐 r/PHP
20
18
February 27, 2021
Add support for JetBrains\PhpStorm\ArrayShape
Currently, PHPStan reports Function execute() return type has no value type specified in iterable type array. when using #[ArrayShape] attribute. More on github.com
🌐 github.com
5
April 1, 2021
🌐
GitHub
github.com › JetBrains › phpstorm-attributes
GitHub - JetBrains/phpstorm-attributes: PhpStorm specific attributes · GitHub
#[ArrayShape([ // 'key' => 'type', 'key1' => 'int', 'key2' => 'string', 'key3' => 'Foo', 'key3' => App\PHP8\Foo::class, ])] function functionName(...): array
Starred by 414 users
Forked by 11 users
Languages   PHP
🌐
JetBrains
blog.jetbrains.com › phpstorm › 2022 › 02 › phpstorm-2022-1-eap-3
PhpStorm 2022.1 EAP #3: Enhanced Array Shapes | The PhpStorm Blog
August 9, 2022 - In PhpStorm 2021.2, we introduced support for array shapes in PHPDoc blocks. It came with a significant limitation, though – only single-line and single-level annotations were supported. To get multiline support, you had the option of using the #[ArrayShape] attribute.
🌐
GitHub
github.com › JetBrains › phpstorm-attributes › blob › master › src › ArrayShape.php
phpstorm-attributes/src/ArrayShape.php at master · JetBrains/phpstorm-attributes
* * Array shapes should be specified with the required $shape parameter whose values should be array literals.<br /> * * Example: <br /> * <b>#[ArrayShape(["f" => "int", "string", "x" => "float"])]</b> * This usage applied on an element ...
Author   JetBrains
🌐
PHPStan
phpstan.org › writing-php-code › phpdoc-types
PHPDoc Types | PHPStan
When a class or function is generic, you specify its type arguments in angle brackets: Collection<int>, Map<string, User>. These types flow through the analysis and PHPStan verifies they are used consistently.
🌐
Long-term
doctum.long-term.support › api-docs › phpstorm-stubs › JetBrains › PhpStorm › ArrayShape.html
JetBrains\PhpStorm\ArrayShape | PHP Jetbrains phpstorm-stubs
Example: #[ArrayShape(["f" => "int", "string", "x" => "float"])] This usage applied on an element effectively means that the array has 3 dimensions, the keys are "f", 1, and "x", and the corresponding types are "int", "string", and "float". ... Generated by Doctum, a API Documentation generator and fork of Sami. This documentation is built using phpstorm...
🌐
Devsense
community.devsense.com › d › 858-array-shapes-and-type-definitions
Array shapes and type definitions - PHP Tools Community Forum | DEVSENSE
Welcome to our community forum. This is an open discussion forum where we try to help and guide you through using Devsense's PHP Tools software. We're here to help!
Find elsewhere
🌐
JetBrains
blog.jetbrains.com › phpstorm › tag › arrayshape
ArrayShape : The PhpStorm Blog | The JetBrains Blog
This major release introduces preliminary support for generics in PHP, enums for PHP 8.1, one-line array shapes, improved automatic formatting of PHP code, new inspections and refactorings, and much more.
🌐
Psalm
psalm.dev › articles › php-8-attributes
Psalm supports PHP 8 Attributes
As an example, it's not clear (unless you understand how attributes can be scoped) which array the ArrayShape attribute refers to here – is it for the parameter type or the return type? use JetBrains\PhpStorm\ArrayShape; #[ArrayShape(["name" => "string", "age" => "int"]) function foo(array $arr) : array
🌐
Reddit
reddit.com › r/programminghorror › i love php array shapes!
r/programminghorror on Reddit: I love php array shapes!
November 20, 2023 - As an array in PHP can also be a hashmap (other key/index type as integer) with the array notation you are able to define the type of the key. e.g. array<string, int> means that the key is a string and the value is an int.
🌐
GitHub
github.com › phpstan › phpstan › discussions › 9223
Array shapes with arbitrary keys · phpstan/phpstan · Discussion #9223
So it seems there's multiple bugs: array shapes are not handled strictly, but once they are I can no longer define this valid use case of PHP arrays.
Author   phpstan
🌐
Phpdoc
docs.phpdoc.org › components › type-resolver › classes › phpDocumentor-Reflection-PseudoTypes-ArrayShape.html
Type Resolver
Represents an array type as described in the PSR-5, the PHPDoc Standard. ... Initializes this representation of an array with the given Type. ... Returns a rendered output of the Type as it would be used in a DocBlock. ... Returns the type for the keys of this array.
🌐
JetBrains
jetbrains.com › help › inspectopedia › PhpArrayShapeCanBeAddedInspection.html
'#[ArrayShape]' attribute can be added | Inspectopedia Documentation
March 4, 2026 - Reports the methods and functions that are returning arrays with known non-trivial keys. Suggests specifying the shape of the returned array via the #[ArrayShape] attribute or an array shape in the PHPDoc comment.
🌐
GitHub
github.com › phpstan › phpstan › issues › 4790
Add support for JetBrains\PhpStorm\ArrayShape · Issue #4790 · phpstan/phpstan
April 1, 2021 - Specifying the shape using ArrayShape annotation should be enough and type could be inferred from it.
Author   simPod
🌐
Devsense
community.devsense.com › d › 583-support-simple-array-shape
Support simple array shape - PHP Tools Community Forum | DEVSENSE
May 27, 2022 - Welcome to our community forum. This is an open discussion forum where we try to help and guide you through using Devsense's PHP Tools software. We're here to help!
🌐
Reddit
reddit.com › r/php › phpstorm 2022.1 eap #3: enhanced array shapes
r/PHP on Reddit: PhpStorm 2022.1 EAP #3: Enhanced Array Shapes
February 21, 2022 - I had written RFC draft for in-language shapes support: https://hackmd.io/@kadet/php-rfc-shapes.
🌐
JetBrains
blog.jetbrains.com › phpstorm › 2021 › 07 › phpstorm-2021-2-release
PhpStorm 2021.2: Generics, Enums, Array Shapes, Inspections, Refactorings, and More | The PhpStorm Blog
September 1, 2021 - This major release introduces preliminary support for generics in PHP, enums for PHP 8.1, one-line array shapes, improved automatic formatting of PHP code, new inspections and refactorings, and much more.