ReflectionProperty::getDeclaringClass

(PHP 5, PHP 7, PHP 8)

ReflectionProperty::getDeclaringClassGets declaring class

说明

public ReflectionProperty::getDeclaringClass(): ReflectionClass

Gets the declaring class.

参数

此函数没有参数。

返回值

A ReflectionClass object.

参见

添加备注

用户贡献的备注 2 notes

up
7
metamarkers at gmail dot com
12 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.<?phpclass 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
4 months ago
Be careful when use getDeclaringClass() for properties from traits<?phptrait 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