← All results

object{foo: int}

Group: Advanced PHPDoc types · Category: ecosystem · File: phpdoc_advanced_fallback_object_shape.php

The object counterpart of an array shape: any object exposing a public foo of type int satisfies it, whatever its class. Two widenings are worth telling apart, because they go wrong in opposite directions — an analyzer that drops the braces and keeps plain object accepts everything, while one that reads the shape as \stdClass rejects a sound instance of a named class. The first shows up as silence on the probes, the second as a complaint about the calls that are meant to pass. References: - PHPStan object shapes, object{foo: int, bar?: string} - Psalm "Object properties", @param object{foo: string} $obj - Intelephense Type-System, object shapes over dynamic properties

Analyzer results

AnalyzerVersionResultDiagnostics
phan 6.0.7Phan 6.0.7 php-ast version 1.1.3 PHP version used to run Phan: 8.5.9 Widened to object

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported

Notes: Accepts the spelling and enforces nothing, though Phan does enforce array shapes and its own `stdClass{...}` notation (phpdoc_advanced_phan_object_shape). The named class carrying `public int $foo` passes, so the widening is to plain `object`, not to `\stdClass`.

phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced reported Lv.5+
phpdoc_advanced_fallback_object_shape.php:51: Parameter #1 $shape of function Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo: int}, Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Mistyped given. [identifier=argument.type] [reported-from-level=5]
phpdoc_advanced_fallback_object_shape.php:54: Parameter #1 $shape of function Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo: int}, Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Unrelated given. [identifier=argument.type] [reported-from-level=5]
With strict-rules
phpdoc_advanced_fallback_object_shape.php:51: Parameter #1 $shape of function Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo: int}, Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Mistyped given. [identifier=argument.type]
phpdoc_advanced_fallback_object_shape.php:54: Parameter #1 $shape of function Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo: int}, Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Unrelated given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Enforced
phpdoc_advanced_fallback_object_shape.php:51: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo:int}, but Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Mistyped provided [InvalidArgument]
phpdoc_advanced_fallback_object_shape.php:54: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo:int}, but Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Unrelated provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mago 1.46.0mago 1.46.0 Enforced
phpdoc_advanced_fallback_object_shape.php:51: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape`: expected `object{foo: int}`, but found `Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Mistyped`. [invalid-argument]
phpdoc_advanced_fallback_object_shape.php:54: Invalid argument type for argument #1 of `Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape`: expected `object{foo: int}`, but found `Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Unrelated`. [invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mir 0.70.1mir 0.70.1 Widened to object

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported

Notes: Accepts the spelling and enforces nothing: both the mistyped and the missing property go through. mir does enforce array shapes (arrays_unsealed_shape), so this is object shapes specifically. It is not read as `\stdClass` either -- the named class carrying `public int $foo` passes.

phpantom 0.9.0phpantom_lsp 0.9.0 Incidental (2/2)
phpdoc_advanced_fallback_object_shape.php:47: Argument 1 ($shape) expects object{foo: int}, got Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Reading [type_mismatch_argument]
phpdoc_advanced_fallback_object_shape.php:51: Argument 1 ($shape) expects object{foo: int}, got Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Mistyped [type_mismatch_argument]
phpdoc_advanced_fallback_object_shape.php:54: Argument 1 ($shape) expects object{foo: int}, got Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Unrelated [type_mismatch_argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 47
Expectation diff
Line 47: Expected valid value to be accepted, got ["Argument 1 ($shape) expects object{foo: int}, got Conformance\\Tests\\PhpdocAdvancedFallbackObjectShape\\Reading [type_mismatch_argument]"]
intelephense 1.18.5intelephense 1.18.5 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported

Notes: Not specific to object shapes: Intelephense does not compare arguments against shapes of either kind, so the array-shape rows are silent too.

phpy 0.2.0phpy 0.2.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported

Notes: Not specific to object shapes: phpy does not compare arguments against shapes of either kind, so the array-shape rows are silent too.

qodana 262.8665.325Qodana 262.8665.325 Widened to object

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported

Notes: Enforces array shapes strictly -- the unsealed rows show it rejecting keys it should admit -- yet checks nothing against an object shape. The named class carrying `public int $foo` passes, so the widening is to plain `object`, not to `\stdClass`.

noverify 0.5.5NoVerify, version 0.5.5: built on: 2025.04.22 14:36:46 OS: r-kuchinskas arm64 Commit: 4774b82f8adc53fbef38f95e97af4b953b4d1529 Unrecognized
phpdoc_advanced_fallback_object_shape.php:42: param $shape miss matched with phpdoc type <<object{foo: int}>> [funcParamTypeMissMatch]
  • Recognition: spelling not resolved — reported on declaration line(s) 42
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved

Notes: Rejects the spelling itself on the declaration line as a docblock/native mismatch, and checks no call site.

steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Widened to object

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported

Notes: Accepts the spelling and enforces nothing, while array shapes are enforced (arrays_unsealed_shape). The named class carrying `public int $foo` passes, so the shape was widened to plain `object` rather than read as `\stdClass`.

phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Enforced
phpdoc_advanced_fallback_object_shape.php:51: Parameter #1 $shape of function Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo: int}, Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Mistyped given. [identifier=argument.type]
phpdoc_advanced_fallback_object_shape.php:54: Parameter #1 $shape of function Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo: int}, Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Unrelated given. [identifier=argument.type]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Enforced
phpdoc_advanced_fallback_object_shape.php:51: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo:int}, but Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Mistyped provided [InvalidArgument]
phpdoc_advanced_fallback_object_shape.php:54: Argument 1 of Conformance\Tests\PhpdocAdvancedFallbackObjectShape\takesObjectShape expects object{foo:int}, but Conformance\Tests\PhpdocAdvancedFallbackObjectShape\Unrelated provided [InvalidArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedFallbackObjectShape;

/**
 * `object{foo: int}`
 *
 * The object counterpart of an array shape: any object exposing a public `foo`
 * of type `int` satisfies it, whatever its class. Two widenings are worth
 * telling apart, because they go wrong in opposite directions — an analyzer
 * that drops the braces and keeps plain `object` accepts everything, while one
 * that reads the shape as `\stdClass` rejects a sound instance of a named
 * class. The first shows up as silence on the probes, the second as a
 * complaint about the calls that are meant to pass.
 *
 * References:
 * - PHPStan object shapes, `object{foo: int, bar?: string}`
 * - Psalm "Object properties", `@param object{foo: string} $obj`
 * - Intelephense Type-System, object shapes over dynamic properties
 */

final class Reading
{
    public int $foo = 1;
}

final class Mistyped
{
    public string $foo = 'one';
}

final class Unrelated
{
    public int $bar = 1;
}

/**
 * @param object{foo: int} $shape
 */
function takesObjectShape(object $shape): void // T: object{foo: int}
{
}

// Any class carrying the declared property qualifies, `stdClass` included.
takesObjectShape(new Reading()); // V
takesObjectShape((object) ['foo' => 1]); // V

// The property is an int,
takesObjectShape(new Mistyped()); // E?: foo is string, not int

// and it has to be there at all.
takesObjectShape(new Unrelated()); // E?: there is no foo property to satisfy the shape