arraylike-object<string, int> is a Psalm-only object refinement$obj[$key] yield the value type; other analyzers do not
recognize the keyword and fall back to accepting any object. The spelling
only resolves in generic form — Psalm's bare arraylike-object is an
unresolvable type, so the key and value type arguments are part of the
spelling under test.
References:
- Psalm arraylike-object structural object refinement| Analyzer | Version | Result | Diagnostics |
|---|---|---|---|
| phan | 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 | Unrecognized ⚠ 1 false positive | phpdoc_advanced_psalm_arraylike_object.php:23: Saw possibly unextractable annotation for a fragment of comment '* @param arraylike-object<string, int> $obj': after arraylike, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_psalm_arraylike_object.php:23: Saw a token Phan may have failed to parse after '* @param arraylike-object<string, int> $obj': after arraylike, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_psalm_arraylike_object.php:25: Parameter $obj has undeclared type \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike [PhanUndeclaredTypeParameter] phpdoc_advanced_psalm_arraylike_object.php:30: Argument 1 ($obj) is new \ArrayObject(['a'=>1]) of type \ArrayAccess|\ArrayObject|\Countable|\IteratorAggregate|\Serializable|\Traversable|iterable but \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike() takes \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_arraylike_object.php:25 [PhanTypeMismatchArgument] phpdoc_advanced_psalm_arraylike_object.php:33: Argument 1 ($obj) is new \stdClass() of type \stdClass but \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike() takes \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_arraylike_object.php:25 [PhanTypeMismatchArgument] phpdoc_advanced_psalm_arraylike_object.php:40: Saw possibly unextractable annotation for a fragment of comment '* @param arraylike-object<string, int> $obj': after arraylike, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName] phpdoc_advanced_psalm_arraylike_object.php:40: Saw a token Phan may have failed to parse after '* @param arraylike-object<string, int> $obj': after arraylike, saw '-' [PhanUnextractableAnnotationSuffix] phpdoc_advanced_psalm_arraylike_object.php:42: Parameter $obj has undeclared type \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike [PhanUndeclaredTypeParameter] phpdoc_advanced_psalm_arraylike_object.php:47: Suspicious array access to $obj of type \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike [PhanTypeArraySuspicious] phpdoc_advanced_psalm_arraylike_object.php:51: Argument 1 ($obj) is new \ArrayObject(['a'=>1]) of type \ArrayAccess|\ArrayObject|\Countable|\IteratorAggregate|\Serializable|\Traversable|iterable but \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\readsElement() takes \Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_arraylike_object.php:42 [PhanTypeMismatchArgument]
Expectation diffLine 47: Expected silence (quiet probe), got ["Suspicious array access to $obj of type \\Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\arraylike [PhanTypeArraySuspicious]"] Line 30: Expected valid value to be accepted, got ["Argument 1 ($obj) is new \\ArrayObject(['a'=>1]) of type \\ArrayAccess|\\ArrayObject|\\Countable|\\IteratorAggregate|\\Serializable|\\Traversable|iterable but \\Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\acceptsArrayLike() takes \\Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\arraylike defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_arraylike_object.php:25 [PhanTypeMismatchArgument]"] Line 51: Unexpected errors ["Argument 1 ($obj) is new \\ArrayObject(['a'=>1]) of type \\ArrayAccess|\\ArrayObject|\\Countable|\\IteratorAggregate|\\Serializable|\\Traversable|iterable but \\Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\readsElement() takes \\Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\arraylike defined at /Users/megurine/repo/php/php-typing-conformance/conformance/tests/phpdoc_advanced_psalm_arraylike_object.php:42 [PhanTypeMismatchArgument]"] |
| phpstan | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Unrecognized reported Lv.max | phpdoc_advanced_psalm_arraylike_object.php:25: Function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike() has parameter $obj with no type specified. [identifier=missingType.parameter] [reported-from-level=6] phpdoc_advanced_psalm_arraylike_object.php:25: PHPDoc tag @param for parameter $obj contains unresolvable type. [identifier=parameter.unresolvableType] [reported-from-level=2] phpdoc_advanced_psalm_arraylike_object.php:42: Function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\readsElement() has parameter $obj with no type specified. [identifier=missingType.parameter] [reported-from-level=6] phpdoc_advanced_psalm_arraylike_object.php:42: PHPDoc tag @param for parameter $obj contains unresolvable type. [identifier=parameter.unresolvableType] [reported-from-level=2] phpdoc_advanced_psalm_arraylike_object.php:47: Cannot access offset 'key' on mixed. [identifier=offsetAccess.nonOffsetAccessible] [reported-from-level=10] phpdoc_advanced_psalm_arraylike_object.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\takesInt expects int, mixed given. [identifier=argument.type] [reported-from-level=10] With strict-rulesphpdoc_advanced_psalm_arraylike_object.php:25: Function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike() has parameter $obj with no type specified. [identifier=missingType.parameter] phpdoc_advanced_psalm_arraylike_object.php:25: PHPDoc tag @param for parameter $obj contains unresolvable type. [identifier=parameter.unresolvableType] phpdoc_advanced_psalm_arraylike_object.php:42: Function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\readsElement() has parameter $obj with no type specified. [identifier=missingType.parameter] phpdoc_advanced_psalm_arraylike_object.php:42: PHPDoc tag @param for parameter $obj contains unresolvable type. [identifier=parameter.unresolvableType] phpdoc_advanced_psalm_arraylike_object.php:47: Cannot access offset 'key' on mixed. [identifier=offsetAccess.nonOffsetAccessible] phpdoc_advanced_psalm_arraylike_object.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\takesInt expects int, mixed given. [identifier=argument.type]
Expectation diffLine 47: Expected silence (quiet probe), got ["Cannot access offset 'key' on mixed. [identifier=offsetAccess.nonOffsetAccessible] [reported-from-level=10]"] |
| psalm | 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac next: 7.0.0-beta19 |
Enforced (pzoom≠) | phpdoc_advanced_psalm_arraylike_object.php:33: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike expects Traversable<string, int>&ArrayAccess<string, int>&Countable, but stdClass provided [InvalidArgument] phpdoc_advanced_psalm_arraylike_object.php:48: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\takesInt cannot be null, possibly null value provided [PossiblyNullArgument] pzoom (Psalm port)No diagnostics from pzoom.
|
| mago | 1.46.0mago 1.46.0 | Unrecognized ⚠ 1 false positive | phpdoc_advanced_psalm_arraylike_object.php:23: Cannot find class, interface, enum, or type alias `Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object`. [non-existent-class-like] phpdoc_advanced_psalm_arraylike_object.php:30: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object)`, but possibly received `ArrayObject<string, int>`. [possibly-invalid-argument] phpdoc_advanced_psalm_arraylike_object.php:33: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object)`, but possibly received `stdClass`. [possibly-invalid-argument] phpdoc_advanced_psalm_arraylike_object.php:40: Cannot find class, interface, enum, or type alias `Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object`. [non-existent-class-like] phpdoc_advanced_psalm_arraylike_object.php:47: Impossible condition: variable `$obj` can never have a non-null entry for key `'key'`. [impossible-nonnull-entry-check] phpdoc_advanced_psalm_arraylike_object.php:47: Assigning `mixed` type to a variable may lead to unexpected behavior. [mixed-assignment] phpdoc_advanced_psalm_arraylike_object.php:48: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\takesInt`: expected `int`, but found `mixed`. [mixed-argument] phpdoc_advanced_psalm_arraylike_object.php:51: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\readsElement`: expected `unknown-ref(Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object)`, but possibly received `ArrayObject<string, int>`. [possibly-invalid-argument]
Expectation diffLine 47: Expected silence (quiet probe), got ["Impossible condition: variable `$obj` can never have a non-null entry for key `'key'`. [impossible-nonnull-entry-check]","Assigning `mixed` type to a variable may lead to unexpected behavior. [mixed-assignment]"] Line 30: Expected valid value to be accepted, got ["Possible argument type mismatch for argument #1 of `Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\acceptsArrayLike`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\arraylike-object)`, but possibly received `ArrayObject<string, int>`. [possibly-invalid-argument]"] Line 51: Unexpected errors ["Possible argument type mismatch for argument #1 of `Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\readsElement`: expected `unknown-ref(Conformance\\Tests\\PhpdocAdvancedPsalmArraylikeObject\\arraylike-object)`, but possibly received `ArrayObject<string, int>`. [possibly-invalid-argument]"] |
| mir | 0.70.1mir 0.70.1 | Partly enforced (1/3) | No diagnostics reported.
|
| phpantom | 0.9.0phpantom_lsp 0.9.0 | Unrecognized | phpdoc_advanced_psalm_arraylike_object.php:23: Class 'Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object<string, int>' not found [unknown_class] phpdoc_advanced_psalm_arraylike_object.php:40: Class 'Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object<string, int>' not found [unknown_class]
|
| intelephense | 1.18.5intelephense 1.18.5 | Partly enforced (2/3) | phpdoc_advanced_psalm_arraylike_object.php:48: Expected type 'int'. Found 'mixed'. [P1006]
|
| phpy | 0.2.0phpy 0.2.0 | Unrecognized | phpdoc_advanced_psalm_arraylike_object.php:23: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object' phpdoc_advanced_psalm_arraylike_object.php:33: Argument '1' passed to Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike() is expected to be of type Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object, stdClass given phpdoc_advanced_psalm_arraylike_object.php:40: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\arraylike-object'
|
| qodana | 262.8665.325Qodana 262.8665.325 | Unrecognized ⚠ 1 false positive | phpdoc_advanced_psalm_arraylike_object.php:23: Undefined class 'arraylike-object' [PhpUndefinedClassInspection] phpdoc_advanced_psalm_arraylike_object.php:30: Parameter 'new \ArrayObject(['a' => 1])' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_psalm_arraylike_object.php:33: Parameter 'new \stdClass()' type is not compatible with declaration [PhpParamsInspection] phpdoc_advanced_psalm_arraylike_object.php:40: Undefined class 'arraylike-object' [PhpUndefinedClassInspection] phpdoc_advanced_psalm_arraylike_object.php:51: Parameter 'new \ArrayObject(['a' => 1])' type is not compatible with declaration [PhpParamsInspection]
Expectation diffLine 30: Expected valid value to be accepted, got ["Parameter 'new \\ArrayObject(['a' => 1])' type is not compatible with declaration [PhpParamsInspection]"] Line 51: Unexpected errors ["Parameter 'new \\ArrayObject(['a' => 1])' type is not compatible with declaration [PhpParamsInspection]"] |
| noverify | 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 | Partly enforced (2/3) | phpdoc_advanced_psalm_arraylike_object.php:48: not null safety call in function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\takesInt signature of param value [notNullSafetyFunctionArgumentVariable]
|
| steins | 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) | Partly enforced (1/3) | No diagnostics reported.
Notes: `arraylike-object` has no `lower_identifier` entry, so it lowers through the catch-all to `ContractTy::Class("arraylike-object")` — Steins has no object-property fact form to check ArrayAccess-like structural membership against. |
| phpstan-strict | 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 | Unrecognized | phpdoc_advanced_psalm_arraylike_object.php:25: Function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike() has parameter $obj with no type specified. [identifier=missingType.parameter] phpdoc_advanced_psalm_arraylike_object.php:25: PHPDoc tag @param for parameter $obj contains unresolvable type. [identifier=parameter.unresolvableType] phpdoc_advanced_psalm_arraylike_object.php:42: Function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\readsElement() has parameter $obj with no type specified. [identifier=missingType.parameter] phpdoc_advanced_psalm_arraylike_object.php:42: PHPDoc tag @param for parameter $obj contains unresolvable type. [identifier=parameter.unresolvableType] phpdoc_advanced_psalm_arraylike_object.php:47: Cannot access offset 'key' on mixed. [identifier=offsetAccess.nonOffsetAccessible] phpdoc_advanced_psalm_arraylike_object.php:48: Parameter #1 $value of function Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\takesInt expects int, mixed given. [identifier=argument.type]
Expectation diffLine 47: Expected silence (quiet probe), got ["Cannot access offset 'key' on mixed. [identifier=offsetAccess.nonOffsetAccessible]"] |
| psalm-next | 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 | Enforced | phpdoc_advanced_psalm_arraylike_object.php:33: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\acceptsArrayLike expects Traversable<string, int>&ArrayAccess<string, int>&Countable, but stdClass provided [InvalidArgument] phpdoc_advanced_psalm_arraylike_object.php:48: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject\takesInt cannot be null, possibly null value provided [PossiblyNullArgument]
|
<?php
declare(strict_types=1);
namespace Conformance\Tests\PhpdocAdvancedPsalmArraylikeObject;
/**
* `arraylike-object<string, int>` is a Psalm-only object refinement.
*
* It matches an object implementing ArrayAccess, Countable and Traversable
* (e.g. ArrayObject). Psalm models it structurally — ArrayAccess makes the
* element access `$obj[$key]` yield the value type; other analyzers do not
* recognize the keyword and fall back to accepting any object. The spelling
* only resolves in generic form — Psalm's bare `arraylike-object` is an
* unresolvable type, so the key and value type arguments are part of the
* spelling under test.
*
* References:
* - Psalm `arraylike-object` structural object refinement
*/
/**
* @param arraylike-object<string, int> $obj
*/
function acceptsArrayLike($obj): void // T: arraylike-object<string, int>
{
}
// ArrayObject implements ArrayAccess, Countable and Traversable.
acceptsArrayLike(new \ArrayObject(['a' => 1])); // V
// A plain object is not array-like; analyzers that model it reject this.
acceptsArrayLike(new \stdClass()); // E?: stdClass is not an arraylike-object
function takesInt(int $value): void
{
}
/**
* @param arraylike-object<string, int> $obj
*/
function readsElement($obj): void // T: arraylike-object<string, int>
{
// The ArrayAccess contract makes element access legal and the value
// typed: $obj['key'] is int, so `?? null` narrows to int|null. A tool
// that fell back to object or mixed reports the offset access here.
$value = $obj['key'] ?? null; // Q: element access is legal via the ArrayAccess contract
takesInt($value); // E?: the element access yields int|null, so the null branch is not int
}
readsElement(new \ArrayObject(['a' => 1]));