Re: Class not used as an object (Scope Resolution Operator)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9 June 2011 22:42, George Langley <george.langley@xxxxxxx> wrote:
> Â Â Â ÂHi all. Am fixing some inherited code, and the previous coder created a class, ie:
>
> class myClass {
> Â Â Â Âfunction &doThis($passedVar) {
> Â Â Â Â Â Â Â ÂdoSomething;
> Â Â Â Â}
>
> Â Â Â Âfunction &doThat($anotherVar) {
> Â Â Â Â Â Â Â ÂdoSomethingElse;
> Â Â Â Â}
> }
>
> BUT, I don't see anywhere where he created an object, ie:
>
> $myObject = new myClass();
>
> or
>
> $myObject =ÂmyClass::doThis("value");
>
> Â Â Â ÂInstead, it's only ever just called directly with a "Scope Resolution Operator",Âie:
>
> myClass::doThis("valueOne");
> myClass::doThat($whatever);
> myClass::doThis("valueTwo");
> myClass::doThat($andSoOn);
>
> Â Â Â ÂIt seems that this would be making an object, and then destroying it again, on each of the four calls above, which I would think would be wasteful - time, memory, cpu usage, etc.
> Â Â Â ÂThe class has no constants or variables (properties) for any need for persistence, and is just a collection of functions (methods), soÂI don't see a reason to group them into a class - they could all reside as independent functions within the php file.
> Â Â Â ÂIs this good? Is there some advantage to making a non-persistent class?
> Â Â Â ÂThanks!

Take a look at http://www.php.net/manual/en/language.oop5.static.php

Static methods are quite useful.

An instance is not created and destroyed. Just the static method is
called without any instance being used.

In the most basic sense, a class with only static methods could be
just a library of unrelated functions and the class is really just a
namespace for these functions.


-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux