NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP5 Static Classes

Matthew Terenzio matt at jobsforge.com
Wed Feb 2 17:20:22 EST 2005


On Feb 2, 2005, at 1:20 PM, Daniel Convissor wrote:

> But, when a class is being used statically, you can use the method
> directly:
>
>   SomeClass::someMethod();
>
> But, be aware that functionality is limited when using classes 
> statically
> because $this is not available inside the methods.

It may help (or not) to think of these objects and methods like static 
web pages, being the same for everyone.
Which is why you can't use $this, because it is not particular to an 
instance of the object, but to the whole class of objects.
Likewise, static methods do not operate on an instance


Object->method();

but as shown in the previous post above, and often taking some action 
on a parameter fed to the method like this worthless example


class MyMathClass {
      public static function squareroot($num) {
         return sqrt($num);
      }
  }

MyMathClass::squareroot(4);




-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2677 bytes
Desc: not available
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20050202/dac01e01/attachment.bin>


More information about the talk mailing list