class NikicPropertyNode implements PropertyNode (View source)

Adapter for nikic/php-parser PropertyItem nodes.

Implements complete PropertyNode interface. Requires both PropertyItem (for name) and Property statement (for modifiers/type).

Traits

Evaluates constant expressions from stub sources to plain PHP values.

Methods

__construct(PropertyItem $property, Property $propertyStmt)

No description

string
getName()

Get the property name.

bool
isPublic()

Check if the property is public.

bool
isProtected()

Check if the property is protected.

bool
isPrivate()

Check if the property is private.

bool
isStatic()

Check if the property is static.

bool
isReadonly()

Check if the property is readonly (PHP 8.1+).

TypeNode|null
getType()

Get the property type, or null if no type hint.

getDocComment()

Get the doc comment, or null if no doc comment.

array
getAttributes()

Get the property attributes (PHP 8.0+).

bool
hasDefaultValue()

Whether the property has a default value, matching ReflectionProperty::hasDefaultValue().

mixed
getDefaultValue()

Evaluate and return the property's default value.

Details

__construct(PropertyItem $property, Property $propertyStmt)

No description

Parameters

PropertyItem $property
Property $propertyStmt

string getName()

Get the property name.

Return Value

string

bool isPublic()

Check if the property is public.

Return Value

bool

bool isProtected()

Check if the property is protected.

Return Value

bool

bool isPrivate()

Check if the property is private.

Return Value

bool

bool isStatic()

Check if the property is static.

Return Value

bool

bool isReadonly()

Check if the property is readonly (PHP 8.1+).

Return Value

bool

TypeNode|null getType()

Get the property type, or null if no type hint.

Return Value

TypeNode|null

DocCommentNode|null getDocComment()

Get the doc comment, or null if no doc comment.

Return Value

DocCommentNode|null

array getAttributes()

Get the property attributes (PHP 8.0+).

Return Value

array

bool hasDefaultValue()

Whether the property has a default value, matching ReflectionProperty::hasDefaultValue().

Note the asymmetry between typed and untyped properties, which is why this is NOT simply "an initializer is present in the source":

  • public $a; untyped, no initializer => true (implicit null default)
  • public $b = 5; untyped, initializer => true
  • public int $c; typed, no initializer => false (uninitialized)
  • public int $d = 7; typed, initializer => true

Reflection reports no untyped property as lacking a default, so an implementation that only checked for an initializer would disagree with reflection on every untyped property.

Return Value

bool

mixed getDefaultValue()

Evaluate and return the property's default value.

Returns null for an untyped property with no initializer — that is its genuine PHP default, even though the runtime may report a different value for an internal class whose C declaration specifies one (e.g. \Exception::$message is protected $message; in the stubs but "" at runtime). Such a difference is a real stub/runtime discrepancy, not an artifact of this method.

Return Value

mixed

The evaluated PHP default value

Exceptions

RuntimeException