Namespace PHPStan\Reflection

Classes
Assertions

Collection of @phpstan-assert annotations on a function or method. PHPStan supports type assertions via PHPDoc annotations:

  • @phpstan-assert Type $param — narrows the parameter type unconditionally
  • @phpstan-assert-if-true Type $param — narrows when the method returns true
  • @phpstan-assert-if-false Type $param — narrows when the method returns false This class collects all such assertions and provides methods to retrieve them by condition type. It also handles negation: an @phpstan-assert-if-true assertion is automatically negated and included in the getAssertsIfFalse() result. Returned by ExtendedMethodReflection::getAsserts() and FunctionReflection::getAsserts().
AttributeReflection

Reflection for a PHP attribute (PHP 8.0+). Represents a single attribute applied to a class, method, property, function, parameter, or constant. Provides the attribute's class name and the types of its constructor arguments. Returned by the getAttributes() method on ExtendedMethodReflection, ExtendedPropertyReflection, FunctionReflection, ClassConstantReflection, etc.

ClassReflection
EnumCaseReflection
ExtendedFunctionVariant
FunctionVariant
GenericParametersAcceptorResolver
InitializerExprContext
InitializerExprTypeResolver
ParametersAcceptorSelector
PassedByReference

Describes how a function/method parameter is passed: by value or by reference. Three modes:

  • No: Passed by value — the argument expression is evaluated and its value is copied.
  • ReadsArgument: Passed by reference, but the function reads the existing variable. The variable must already exist. Example: sort(&$array).
  • CreatesNewVariable: Passed by reference, and the function may create the variable if it doesn't exist. Example: preg_match($pattern, $subject, &$matches) where $matches doesn't need to be defined beforehand. This distinction matters for PHPStan's scope analysis — when a function takes a parameter by reference with "creates new variable" semantics, PHPStan knows the variable will exist after the call even if it wasn't defined before. Used as the return type of ParameterReflection::passedByReference().
TrivialParametersAcceptor
Interfaces
AdditionalConstructorsExtension

This is the extension interface to implement if you want to dynamically mark methods as constructor. As opposed to simply list them in the configuration file. To register it in the configuration file use the phpstan.additionalConstructorsExtension service tag: ``` services: - class: App\PHPStan\MyExtension tags: - phpstan.additionalConstructorsExtension

AllowedSubTypesClassReflectionExtension

This is the extension interface to implement if you want to described allowed subtypes - to limit which classes can implement a certain interface or extend a certain parent class. To register it in the configuration file use the phpstan.broker.allowedSubTypesClassReflectionExtension service tag: ``` services: - class: App\PHPStan\MyExtension tags: - phpstan.broker.allowedSubTypesClassReflectionExtension

ClassConstantReflection

Reflection for a class constant. Combines ClassMemberReflection (declaring class, visibility) with ConstantReflection (name, value type, deprecation) and adds class-constant-specific features: the value expression AST, final modifier, and separate PHPDoc/native types. PHP 8.3+ supports native type declarations on class constants, so this interface provides both PHPDoc and native type accessors (similar to property reflection). This is the return type of Type::getConstant() and Scope::getConstantReflection().

ClassMemberAccessAnswerer

Answers questions about visibility and access rights for class members (properties, methods, constants) from the current analysis context. This interface is the Scope's role as an access control checker. It is passed as a parameter to Type methods like getMethod(), getProperty(), getConstant(), etc., so the type system can enforce visibility rules (public/protected/private) based on where the access occurs. The primary implementation is MutatingScope. A secondary implementation, OutOfClassScope, is used when accessing members from outside any class.

ClassMemberReflection

Base interface for all class members: properties, methods, and constants. Provides common metadata shared by all class members — their declaring class, visibility (public/private/protected), static-ness, and raw PHPDoc comment. This is the parent interface for PropertyReflection, MethodReflection, and (via ConstantReflection) ClassConstantReflection. Extension developers typically work with the more specific child interfaces.

ConstantReflection

Reflection for a constant (class constant or global constant). Provides the constant's name, resolved value type, deprecation status, and metadata. This is the base interface — ClassConstantReflection extends it with class-specific features (declaring class, value expression, native type).

ExtendedMethodReflection

Extended method reflection with additional metadata beyond MethodReflection. This interface exists to allow PHPStan to add new method query methods in minor versions without breaking existing MethodsClassReflectionExtension implementations. Extension developers should implement MethodReflection, not this interface — PHPStan wraps MethodReflection implementations to provide ExtendedMethodReflection. Provides access to:

  • Extended parameter signatures (ExtendedParametersAcceptor with PHPDoc/native types)
  • Named argument variants (different signatures when using named arguments)
  • Type assertions (@phpstan-assert annotations)
  • Self-out types (@phpstan-self-out for fluent interfaces)
  • Purity information (@phpstan-pure/@phpstan-impure)
  • PHP attributes (including #[\NoDiscard])
  • Resolved PHPDoc block This is the return type of Type::getMethod() and Scope::getMethodReflection().
ExtendedParameterReflection
ExtendedParametersAcceptor

Extended function/method signature with separate PHPDoc and native types. Extends ParametersAcceptor with:

  • Extended parameter reflections (separate PHPDoc/native types per parameter)
  • Separate PHPDoc and native return types (vs the combined return type from ParametersAcceptor)
  • Call-site variance map for template type parameters This is the return type of FunctionReflection::getVariants() and ExtendedMethodReflection::getVariants().
ExtendedPropertyReflection

Extended property reflection with additional metadata beyond PropertyReflection. This interface exists to allow PHPStan to add new property query methods in minor versions without breaking existing PropertiesClassReflectionExtension implementations. Extension developers should implement PropertyReflection, not this interface — PHPStan wraps PropertyReflection implementations to provide ExtendedPropertyReflection. Provides access to:

  • Separate PHPDoc type vs native type (for resolving the effective type)
  • Property hooks (PHP 8.4+) — get/set hooks with their own method reflections
  • Asymmetric visibility (PHP 8.4+) — different read/write visibility
  • Abstract/final/virtual modifiers
  • PHP attributes This is the return type of Type::getProperty(), Type::getInstanceProperty(), and Type::getStaticProperty().
FunctionReflection

Reflection for a standalone function (not a class method). Represents both built-in PHP functions and user-defined functions. Like methods, functions can have multiple "variants" (overloaded signatures) — particularly common for built-in functions where the return type depends on argument types. Extension developers encounter this interface when implementing DynamicFunctionReturnTypeExtension or FunctionTypeSpecifyingExtension. Functions referenced in Scope::getFunctionCallStack() may be either FunctionReflection or MethodReflection.

MethodReflection

Reflection for a class method. This is the interface extension developers should implement when creating custom MethodsClassReflectionExtension implementations for magic methods (__call, etc.). Methods can have multiple "variants" (overloaded signatures) — for example, built-in functions like array_map have different signatures depending on the number of arguments. Each variant is a ParametersAcceptor. For additional method metadata (assertions, purity, named arguments, attributes), see ExtendedMethodReflection which extends this interface.

MethodsClassReflectionExtension

This is the interface custom methods class reflection extensions implement. To register it in the configuration file use the phpstan.broker.methodsClassReflectionExtension service tag: ``` services: - class: App\PHPStan\MyMethodsClassReflectionExtension tags: - phpstan.broker.methodsClassReflectionExtension

NamespaceAnswerer

Provides the current namespace context. Used by the type resolver and PHPDoc parser to resolve relative class names against the current namespace and use statements.

ParameterReflection

Reflection for a function/method parameter. Represents a single parameter in a function or method signature. Each parameter has a name, type, and metadata about optionality, variadicity, and pass-by-reference. The type returned by getType() is the combined PHPDoc + native type. For separate PHPDoc and native types, see ExtendedParameterReflection. Part of a ParametersAcceptor which describes a complete function signature.

ParametersAcceptor

Describes one signature variant of a function or method. A function/method may have multiple ParametersAcceptor variants — for example, the built-in strtok function has different signatures depending on argument count. Each variant describes the template type parameters, positional parameters, variadicity, and return type. This is the base interface. ExtendedParametersAcceptor adds separate PHPDoc/native return types and extended parameter reflection. CallableParametersAcceptor adds throw points, impure points, and purity information. Use ParametersAcceptorSelector to choose the best variant for a given call site.

PropertiesClassReflectionExtension

This is the interface custom properties class reflection extensions implement. To register it in the configuration file use the phpstan.broker.propertiesClassReflectionExtension service tag: ``` services: - class: App\PHPStan\MyPropertiesClassReflectionExtension tags: - phpstan.broker.propertiesClassReflectionExtension

PropertyReflection

Reflection for a class property. This is the interface extension developers should implement when creating custom PropertiesClassReflectionExtension implementations for magic properties. Properties have separate readable and writable types to support:

  • Asymmetric types (PHP 8.4+ property hooks with different get/set types)
  • Read-only properties (readable but not writable)
  • Write-only properties (writable but not readable, rare) For additional property metadata (native types, PHPDoc types, hooks, attributes), see ExtendedPropertyReflection which extends this interface.
ReflectionProvider
Namespaces
PHPStan\Reflection\Callables
PHPStan\Reflection\Deprecation
PHPStan\Reflection\Php