gpt4 book ai didi

php - 获取实例的静态属性

转载 作者:IT王子 更新时间:2023-10-29 00:11:37 24 4
gpt4 key购买 nike

如果我在 PHP 中有一个实例,获取该实例的静态属性(“类变量”)的最简单方法是什么?

这个

$classvars=get_class_vars(get_class($thing));
$property=$classvars['property'];

听起来确实过头了。我希望

$thing::property

$thing->property

EDIT: this is an old question. There are more obvious ways to do this in newer PHP, search below.

最佳答案

您需要先查找类名:

$class = get_class($thing);
$class::$property

当然,$property 必须定义为 staticpublic

关于php - 获取实例的静态属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5623846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com