ReflectionProperty Sınıfı

(PHP 5, PHP 7, PHP 8)

Giriş

ReflectionProperty sınıfı sınıfın özellikleri hakkında bilgi edinilmesini sağlar.

Sınıf Sözdizimi

class ReflectionProperty implements Reflector {
/* Sabitler */
public const int IS_STATIC;
public const int IS_READONLY;
public const int IS_PUBLIC;
public const int IS_PROTECTED;
public const int IS_PRIVATE;
/* Özellikler */
public string $name;
public string $class;
/* Yöntemler */
public function __construct(object|string $class, string $property)
private function __clone(): void
public static function export(mixed $sınıf, string $isim, bool $ihracet = ?): string
public function getAttributes(?string $name = null, int $flags = 0): array
public function getDefaultValue(): mixed
public function getDocComment(): string|false
public function getHooks(): array
public function getModifiers(): int
public function getName(): string
public function getRawValue(object $object): mixed
public function getSettableType(): ?ReflectionType
public function getType(): ?ReflectionType
public function getValue(?object $nesne = null): mixed
public function hasDefaultValue(): bool
public function hasHook(PropertyHookType $type): bool
public function hasHooks(): bool
public function hasType(): bool
public function isAbstract(): bool
public function isDefault(): bool
public function isDynamic(): bool
public function isFinal(): bool
public function isInitialized(?object $object = null): bool
public function isLazy(object $object): bool
public function isPrivate(): bool
public function isPrivateSet(): bool
public function isPromoted(): bool
public function isProtected(): bool
public function isProtectedSet(): bool
public function isPublic(): bool
public function isReadOnly(): bool
public function isStatic(): bool
public function isVirtual(): bool
public function setAccessible(bool $erişilebilir): void
public function setRawValue(object $object, mixed $value): void
public function setRawValueWithoutLazyInitialization(object $object, mixed $value): void
public function setValue(object $nesne, mixed $değer): void
public function setValue(mixed $değer): void
public function skipLazyInitialization(object $object): void
public function __toString(): string
}

Özellikler

name

Özelliğin ismi. Salt-okunur olup, bir yazma çabası ReflectionException istisnasına yol açar.

class

Özelliği tanımlayan sınıfın ismi. Salt-okunur olup, bir yazma çabası ReflectionException istisnasına yol açar.

Öntanımlı Sabitler

ReflectionProperty Değiştiricileri

ReflectionProperty::IS_STATIC

Özelliğin static olduğunu belirtir. PHP 7.4.0 öncesinde, bu değer 1 idi.

ReflectionProperty::IS_READONLY

Özelliğin salt okunur olduğunu belirtir. PHP 8.1.0 ve sonrasında kullanılabilir.

ReflectionProperty::IS_PUBLIC

Özelliğin public olduğunu belirtir. PHP 7.4.0 öncesinde, bu değer 256 idi.

ReflectionProperty::IS_PROTECTED

Özelliğin protected olduğunu belirtir. PHP 7.4.0 öncesinde, bu değer 512 idi.

ReflectionProperty::IS_PRIVATE

Özelliğin private olduğunu belirtir. PHP 7.4.0 öncesinde, bu değer 1024 idi.

Bilginize:

Sabitlerin değerleri PHP sürümleri arasında farklılık gösterebilir. Bu bakımdan sabitler değerleriyle değil isimleriyle kullanılmalıdır.

Sürüm Bilgisi

Sürüm: Açıklama
8.0.0 ReflectionProperty::export() kaldırıldı.

İçindekiler

add a note

User Contributed Notes 1 note

up
7
rasmus at mindplay dot dk
15 years ago
I think a more accurate explanation is this:

The Reflection classes are designed to reflect upon the source code of an application, not on any runtime information.

I think you misunderstand the ReflectionProperty constructor in your example above. The fact that it accepts an object as argument is just a convenience feature - you are actually inspecting the class of that object, not the object itself, so it's basically equivalent to:

<?php

// works fine 
$Reflection = new ReflectionProperty(get_class($a), 'a');

// throws exception 
$Reflection = new ReflectionProperty(get_class($a), 'foo');

?>

Getting the class of the object you're passing in is implied, since inspecting a defined property is the purpose of this class.

In your example, $a->foo is a dynamic member - it is not defined as a member of class, so there is no defining class reference, line number, default value, etc. - which means, there is nothing to reflect upon.

Clearly this very useful library could use some real documentation...
To Top