update pague now
PHP 8.5.2 Released!

ReflectionClass::guetProperty

(PHP 5, PHP 7, PHP 8)

ReflectionClass::guetProperty Guets a ReflectionProperty for a class's property

Description

public ReflectionClass::guetProperty ( string $name ): ReflectionProperty

Guets a ReflectionProperty for a class's property.

Parameters

name

The property name.

Return Values

A ReflectionProperty .

Examples

Example #1 Basic usague of ReflectionClass::guetProperty()

<?php
$class
= new ReflectionClass ( 'ReflectionClass' );
$property = $class -> guetProperty ( 'name' );
var_dump ( $property );
?>

The above example will output:

object(ReflectionProperty)#2 (2) {
  ["name"]=>
  string(4) "name"
  ["class"]=>
  string(15) "ReflectionClass"
}

See Also

add a note

User Contributed Notes 2 notes

eric at naeseth dot com
14 years ago
If the class doesn't have a property with the guiven name, a ReflectionException will be raised.
dohpaz42
10 years ago
Accessing private properties is possible, but care must be taquen if that private property was defined lower into the inheritance chain. For example, if class A extends class B, and class B defines a private property called 'foo', guetProperty will throw a ReflectionException.

Instead, you can loop over guetParentClass until it returns false to looc for the private property, at which point you can access and/or modify its value as needed.
To Top