I agree that a plain old function would be the best solution in this situation. I think classes full of static methods provide no real value, from an object-oriented design perspective. All you get is a bunch of extra typing.

It's true the framework currently has no place for normal function libraries, but, personally, I think it would be better to make one than to start introducing such static classes. The core contributors to this framework are really smart people; they should be more than capable of keeping these kinds of function libraries from getting out of control.

Just my $0.02,
Bryce Lohr


Jack Sleight wrote:

Shahar Evron wrote:

True, a function is a natural solution - but I think most core people
would consider adding functions to ZF to be against all design concepts.
There is a middle path of course - utility classes grouping static
methods.
Yeah, I guess that in order to fit in with the framework design static classes would make the most sense. I didn't suggest it because I've read articles by people that say you shouldn't use classes for simply grouping static methods; but to be honest I don't really see why it matters so much, especially if it solves a common problem.
class Zend_Utility_String {
    /**
     * Calculate the byte-length of a string
     *
     * @param  string  $string      * @return integer String length
     */
    static public function ByteLength($string);

    /**
     * Split a string into words, grouping quoted phrases together
     *
* @param string $string * @param string $groupBy * @return array Tokenized words
     */
    static public function tokenize($string, $groupBy = '"');

        static public function ...
}

class Zend_Utility_Math
{
    static public function ...
}

// .. and so on - // I'd even rename classes like Zend_Debug to Zend_Utility_Debug...

Yeah, I think something like this would be very beneficial, and I'm sure the need for utility methods will come up again. In fact there are probably quite a few static methods in the framework already that could be refactored into such classes, to make them easily available.

Reply via email to