On 9 June 2011 22:42, George Langley <george.lang...@shaw.ca> 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

Reply via email to