2

我已经看到这两种方法都用于 PHP 库的文档中(似乎可以互换),并且想知道是否有一种疯狂的方法以及应该使用每种方法的时间?(或者,如果它们的含义不同,那么我在文档中遗漏了一个细微差别)

例子:

ClassName#foo()  // a method
ClassName::bar() // a method
ClassName::baz   // a property

我还没有(还)见过有人尝试使用ClassName#qux房产,但也许这也是可能的!

希望这篇文章能帮助人们走上正轨!

提前致谢

PS这很难搜索谷歌。“#” = “hash” = “pound” 和 “::” = “双冒号” = “T_PAAMAYIM_NEKUDOTAYIM”... 当然,“hash” 也有其自身的含义。

ClassName::foo编辑:另一个问题是将属性和变量记录为或ClassName::$foo(即有或没有前导$)是否正常/正确

4

2 回答 2

2

即使对于 PHP,它也是反常的,这说明了很多。永远不要在任何情况下这样做。

于 2013-07-26T14:46:21.720 回答
1

It is probably to disambiguate between actual static methods which can literally be called with Foo::bar(), and instance methods which require an object instance, like $foo->bar(). That's the only sensible explanation I can think of, and it's not an official standard in any context that I'm aware of.

于 2013-07-26T14:42:34.907 回答