ReflectionProperty::getDeclaringClass

(PHP 5, PHP 7, PHP 8)

ReflectionProperty::getDeclaringClassПолучает класс, в котором объявили свойство

Описание

public ReflectionProperty::getDeclaringClass(): ReflectionClass

Метод получает название класса, в котором объявили свойство.

Список параметров

У этой функции нет параметров.

Возвращаемые значения

Метод возвращает объект класса ReflectionClass.

Смотрите также

Добавить

Примечания пользователей 2 notes

up
7
metamarkers at gmail dot com
11 years ago
If you're reflecting an object and get the declaring class of a property that's set but wasn't declared in any class, it returns the class of the instance.

<?php

class X {

}

$x = new X();
$x->foo = 'bar';
$reflection = new ReflectionObject($x);
echo
$reflection->getProperty('foo')->getDeclaringClass()->getName(); // X

?>
up
0
kp42 at ya dot ru
8 days ago
Be careful when use getDeclaringClass() for properties from traits

<?php

trait Y {
public
$y;
}

class
X {
use
Y;
}

$x = new X();
$x->y = 42;
$reflection = new ReflectionObject($x);
echo
$reflection->getProperty('y')->getDeclaringClass()->getName(); // X

?>
To Top