← All results

public-properties-of<T> is a Psalm visibility-filtered utility type

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

Sibling of properties-of<T> that only expands *public* non-static properties. Psalm also documents protected-properties-of and private-properties-of; this file probes the public variant. References: - Psalm utility_types.md: properties-of variants

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 Unrecognized
phpdoc_advanced_psalm_public_properties_of.php:34: Saw possibly unextractable annotation for a fragment of comment '* @param public-properties-of<User> $data': after public, did not see an element name (will guess based on comment order) [PhanUnextractableAnnotationElementName]
phpdoc_advanced_psalm_public_properties_of.php:34: Saw a token Phan may have failed to parse after '* @param public-properties-of<User> $data': after public, saw '-' [PhanUnextractableAnnotationSuffix]
  • Recognition: spelling not resolved — reported on declaration line(s) 34
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
phpstan 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Unrecognized
phpdoc_advanced_psalm_public_properties_of.php:36: Function Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps() has parameter $data with no value type specified in iterable type array. [identifier=missingType.iterableValue] [reported-from-level=6]
phpdoc_advanced_psalm_public_properties_of.php:36: PHPDoc tag @param for parameter $data contains unresolvable type. [identifier=parameter.unresolvableType] [reported-from-level=2]
With strict-rules
phpdoc_advanced_psalm_public_properties_of.php:36: Function Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps() has parameter $data with no value type specified in iterable type array. [identifier=missingType.iterableValue]
phpdoc_advanced_psalm_public_properties_of.php:36: PHPDoc tag @param for parameter $data contains unresolvable type. [identifier=parameter.unresolvableType]
  • Recognition: spelling not resolved — reported on declaration line(s) 36
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
psalm 6.16.1Psalm 6.16.1@f1f5de594dc76faf8784e02d3dc4716c91c6f6ac
next: 7.0.0-beta19
Enforced
phpdoc_advanced_psalm_public_properties_of.php:44: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps expects array{name: string}, but array{age: 42, name: 'Ada'} with additional array shape fields (age) was provided [InvalidArgument]
phpdoc_advanced_psalm_public_properties_of.php:47: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps expects array{name: string}, but array{name: 1} provided [InvalidScalarArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mago 1.46.0mago 1.46.0 Enforced
phpdoc_advanced_psalm_public_properties_of.php:44: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps`: expected `array{'name': string}`, but possibly received `array{'age': int(42), 'name': string('Ada')}`. [possibly-invalid-argument]
phpdoc_advanced_psalm_public_properties_of.php:47: Possible argument type mismatch for argument #1 of `Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps`: expected `array{'name': string}`, but possibly received `array{'name': int(1)}`. [possibly-invalid-argument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported
mir 0.70.1mir 0.70.1 Incidental (2/2)
phpdoc_advanced_psalm_public_properties_of.php:41: InvalidArgument: Argument $data of acceptsPublicUserProps() expects 'Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\public-properties-of<Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\User>', got 'array{'name': "Ada"}' [MIR0201]
phpdoc_advanced_psalm_public_properties_of.php:44: InvalidArgument: Argument $data of acceptsPublicUserProps() expects 'Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\public-properties-of<Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\User>', got 'array{'name': "Ada", 'age': 42}' [MIR0201]
phpdoc_advanced_psalm_public_properties_of.php:47: InvalidArgument: Argument $data of acceptsPublicUserProps() expects 'Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\public-properties-of<Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\User>', got 'array{'name': 1}' [MIR0201]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported — incidental, since values the type admits were also rejected on line(s) 41
Expectation diff
Line 41: Expected valid value to be accepted, got ["InvalidArgument: Argument $data of acceptsPublicUserProps() expects 'Conformance\\Tests\\PhpdocAdvancedPsalmPublicPropertiesOf\\public-properties-of<Conformance\\Tests\\PhpdocAdvancedPsalmPublicPropertiesOf\\User>', got 'array{'name': \"Ada\"}' [MIR0201]"]
phpantom 0.9.0phpantom_lsp 0.9.0 Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
intelephense 1.18.5intelephense 1.18.5 Not enforced
phpdoc_advanced_psalm_public_properties_of.php:34: Documented type is not compatible with the declared type. [P1131]
  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpy 0.2.0phpy 0.2.0 Unrecognized
phpdoc_advanced_psalm_public_properties_of.php:34: Use of unknown class: 'Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\public-properties-of'
  • Recognition: spelling not resolved — reported on declaration line(s) 34
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
qodana 262.8665.325Qodana 262.8665.325 Unrecognized
phpdoc_advanced_psalm_public_properties_of.php:34: Argument type does not match the declared [PhpDocSignatureInspection]
phpdoc_advanced_psalm_public_properties_of.php:34: Undefined class 'public-properties-of' [PhpUndefinedClassInspection]
  • Recognition: spelling not resolved — reported on declaration line(s) 34
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
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_psalm_public_properties_of.php:36: param $data miss matched with phpdoc type <<public-properties-of<User>>> [funcParamTypeMissMatch]
  • Recognition: spelling not resolved — reported on declaration line(s) 36
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
steins 0.1.5steins 0.1.5 (2026-08-12 revision 39b4cc1) Not enforced

No diagnostics reported.

  • Recognition: spelling resolved
  • Enforcement: 0/2 of the expected violations reported
phpstan-strict 2.2.8PHPStan - PHP Static Analysis Tool 2.2.8 Unrecognized
phpdoc_advanced_psalm_public_properties_of.php:36: Function Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps() has parameter $data with no value type specified in iterable type array. [identifier=missingType.iterableValue]
phpdoc_advanced_psalm_public_properties_of.php:36: PHPDoc tag @param for parameter $data contains unresolvable type. [identifier=parameter.unresolvableType]
  • Recognition: spelling not resolved — reported on declaration line(s) 36
  • Enforcement: 0/2 of the expected violations reported — incidental, since the spelling was not resolved
psalm-next 7.0.0-beta19Psalm 7.0.0-beta19@7e751c06a756fa64dc4c759c09fe4a173afcb433 Enforced
phpdoc_advanced_psalm_public_properties_of.php:44: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps expects array{name: string}, but array{age: 42, name: 'Ada'} with additional array shape fields (age) was provided [InvalidArgument]
phpdoc_advanced_psalm_public_properties_of.php:47: Argument 1 of Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf\acceptsPublicUserProps expects array{name: string}, but array{name: 1} provided [InvalidScalarArgument]
  • Recognition: spelling resolved
  • Enforcement: 2/2 of the expected violations reported

Source

<?php

declare(strict_types=1);

namespace Conformance\Tests\PhpdocAdvancedPsalmPublicPropertiesOf;

/**
 * `public-properties-of<T>` is a Psalm visibility-filtered utility type.
 *
 * Sibling of `properties-of<T>` that only expands *public* non-static
 * properties. Psalm also documents `protected-properties-of` and
 * `private-properties-of`; this file probes the public variant.
 *
 * References:
 * - Psalm utility_types.md: properties-of variants
 */

final class User
{
    public string $name = '';

    protected int $age = 0;

    private string $secret = '';

    public function describe(): string
    {
        // Touch non-public fields so unused-property rules stay quiet.
        return $this->name . (string) $this->age . $this->secret;
    }
}

/**
 * @param public-properties-of<User> $data
 */
function acceptsPublicUserProps(array $data): void // T: public-properties-of<User>
{
}

// Only the public property is required / accepted by the shape.
acceptsPublicUserProps(['name' => 'Ada']); // V

// A non-public property key is not part of public-properties-of<User>.
acceptsPublicUserProps(['name' => 'Ada', 'age' => 42]); // E?: age is protected, not in public-properties-of

// Wrong type on the public property.
acceptsPublicUserProps(['name' => 1]); // E?: name must be string in public-properties-of<User>