php静态方法

编程入门 行业动态 更新时间:2024-10-26 12:23:36
php静态方法 - “静态函数”和“公共静态函数”有什么区别?(php static methods - what is the difference between “static function” and “public static function”?)

正如标题所说,我似乎无法看到公共静态与普通旧静态之间的差异。即

public static function visitorUserCreate( $data ) {}

static function visitorUserCreate( $data ) {}

两者似乎都是公开的,如果它们是默认声明公开的重点是什么?

As the title says i cannot seem to see what the difference is between a public static and just a plain old static.. ie

public static function visitorUserCreate( $data ) {}

and

static function visitorUserCreate( $data ) {}

Both appear to be public, if they are what is the point in declaring public if it is by default?

最满意答案

从静态关键字的PHP手册文档 :

为了与PHP 4兼容,如果未使用可见性声明,则将属性或方法视为声明为public。

回答你的问题:

两者似乎都是公开的,如果它们是默认声明公开的重点是什么?

没有。 宣布公开的目的是为了提高可读性。 在编译器级别没有区别,但是通常很好的设计来声明它。

From the PHP manual documentation for Static Keywords:

For compatibility with PHP 4, if no visibility declaration is used, then the property or method will be treated as if it was declared as public.

To answer your question:

Both appear to be public, if they are what is the point in declaring public if it is by default?

None. The point of declaring public is for readability. There is no difference at compiler level, however it's usually good design to declare it.

更多推荐

本文发布于:2023-04-28 00:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329636.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   方法   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!