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.
--
Jack

Reply via email to