大佬教程收集整理的这篇文章主要介绍了应该使用PHP类吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
if (!class_exists('example')) {
class example {
# Declare ~20 functions (methods), all of
# which are public. (There's nothing else
# in the class.)
public static function one() { /* ... */ }
public static function two() { /* ... */ }
# ...
} # class
}
使方法可用为:
example::one();
example::two();
与简单地执行此操作相比,上述方法有哪些优点/缺点:
if (!defined('EXAMPLE_LOADED')) {
define('EXAMPLE_LOADED', truE);
function example_one() { /* ... */ }
function example_two() { /* ... */ }
# ...
}
使功能可用:
example_one();
example_two();
编辑-相关性能测试:
> function calls from global/class/namespace
> function calls in
classes, namespaces
> properties vs. global variables vs. constants
解决方法:
When to use static vs instantiated classes
我还要说的是,我之前已经将类似的函数分组为纯静态类.我喜欢它提供的语法糖.
format::usaPhone( $val );
format::usaZip( $val );
date::convertTz( $date, $tz1, $tz2 );
像那样的东西.我建议您对此务实,并确保最终所做的事情满足两件事.
>您对结果感到满意.
>结果代码很有意义.
这听起来像是对显而易见的陈述,但这是一个很好的提醒,当一个简单的解决方案出现时,不要过分思考.
以上是大佬教程为你收集整理的应该使用PHP类吗?全部内容,希望文章能够帮你解决应该使用PHP类吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。