I've seen both used in documentation of a PHP library (seemingly interchangeably) and was wondering if there's a method to the madness and a time when each should be used? (Or if they mean something different, a nuance which I've therefore missed in the documentation)
Examples:
ClassName#foo() // a method
ClassName::bar() // a method
ClassName::baz // a property
I've not (yet) seen anybody try to use ClassName#qux
for a property but perhaps that's possible too!
Hopefully this thread will help to set people on the straight and narrow!
Thanks in advance
P.S. it's hard searching Google for this. "#" = "hash" = "pound" and "::" = "double colon" = "T_PAAMAYIM_NEKUDOTAYIM"... and "hash" means something all of its own too, of course.
Edit: A further question is whether it is normal/correct to document properties and variables as ClassName::foo
or ClassName::$foo
(i.e. with or without a leading $)
Even for PHP, it's perverse, which is saying a lot. Don't ever do it in any context.
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.