略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionProperty::getDeclaringClass

2024-04-28

ReflectionProperty::getDeclaringClass

(PHP 5, PHP 7, PHP 8)

ReflectionProperty::getDeclaringClassGets declaring class

说明

public ReflectionProperty::getDeclaringClass(): ReflectionClass

Gets the declaring class.

参数

此函数没有参数。

返回值

A ReflectionClass object.

参见

add a noteadd a note

User Contributed Notes 1 note

up
5
metamarkers at gmail dot com
9 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

?>

官方地址:https://www.php.net/manual/en/reflectionproperty.getdeclaringclass.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3