为什么要在 PHP 中使用静态调用? [英] Why should we use static calls in PHP?

查看:87
本文介绍了为什么要在 PHP 中使用静态调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们要在 PHP5 中使用静态变量或静态调用静态方法?也许是为了提高性能?

Why should we use static variables or static calls to static methods in PHP5? Maybe to improve performance?

推荐答案

我们使用静态类变量在类的所有实例之间共享数据,并且我们使用静态方法(最好是private static)计算类功能所需的东西,但独立于类实例状态($this).

We use static class variables to share data between all the instances of the class, and we use static methods (preferably private static) to compute something required for the class functionality, but independent of the class instance state ($this).

性能真的不是 static-s 存在的原因.这更像是一种副作用.

Performance is really not the reason for the existence of static-s. It's more like a side effect.

这篇关于为什么要在 PHP 中使用静态调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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