如何判断我是静态的还是物体? [英] How to tell whether I'm static or an object?

查看:81
本文介绍了如何判断我是静态的还是物体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道您是通过静态方法(类名::函数)还是在PHP方法中的对象($ classInstance->函数)内部知道该方法吗?

Does anybody know offhand the way to tell whether I'm being called statically (Classname::function) or inside an object ($classInstance->function) inside a PHP method?

推荐答案

诚然没有副手……但肖恩·科茨(Sean Coates)的

Admittedly not offhand...but Sean Coates has a cool and fairly simple approach to finding this out:

$isStatic = !(isset($this) && get_class($this) == __CLASS__);

这篇关于如何判断我是静态的还是物体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆