|
Posted by Oli Filth on 05/26/06 15:04
gg9h0st said the following on 26/05/2006 09:36:
> i really wander what makes static method special?
>
> in fact i can access a non static method statically using '::'
>
> class aclass {
> function anonstatic() {
> echo 'non static';
> }
>
> static function astatic() {
> echo 'static';
> }
> }
>
> $aobj = new aclass();
>
> aclass::anonstatic();
> //it works.
>
> $aobj->astatic();
> //it works too.
>
> i see a diffrence that i can't use $this in static method but nothing.
>
> i don't feel there's no reason i have to make a mothod static.
>
> is there any reason i have to declare a mothod as static?
Static methods and variables are useful when you want to share
information between objects of a class, or want to represent something
that's related to the class itself, not any particular object.
For some reason, PHP allows you to call non-static and static methods
interchangeably, which as far as I can see, makes *no* sense at all,
neither from a semantic nor a programmatic point of view.
--
Oli
Navigation:
[Reply to this message]
|