Hi, On Fri, 2007-10-26 at 18:52 +0100, Jack Sleight wrote: > This may go against the intended design of the framework in the first > place, but in a typical application such a function would just be a > standard function, not part of any class. There's no doubt that there > are plenty of gaps in the functions that come with PHP, so a problem > like this may well crop up again. >
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.
> Couldn't the framework introduce a standard way of defining these
> utility functions, which could easily be included by Zend_Loader?
Yes - as static class methods ;)
This of course depends on real need - I currently only have one itch to
scratch - but there might be more similar itches, that might be grouped
into related classes - for example:
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...
?>
Of course, this approach depends on actual need - since I don't have
good examples, I can't say there really is a need.
Shahar.
> I've run into the same problem myself when developing a set of my own
> components that work with/extend ZF. Currently I just have a folder
> called "functions", at the same level as the "library" folder, which
> contains a few PHP files with all my additional functions.
>
> Just a thought.
>
> Shahar Evron wrote:
> > Hi all,
> >
> > I am working on one of the Http_Client bugs, ZF-2098, which describes a
> > problem the Http_Client has when sending multi-byte encoded (eg. UTF8
> > Chinese) text in the request body when mbstring is loaded and overloads
> > the strlen() function. This happens because I've been using strlen() to
> > calculate the body size (in bytes - not in characters).
> >
> > This works in most cases, but when mbstring overloads strlen with
> > mb_strlen - what you get is the string length in characters and not in
> > bytes.
> >
> > Brian DeShong already proposed a patch fixing the problem, but I've
> > found that there are several Zend_Http classes that suffer from the same
> > problem. I'm sure that other ZF classes, as well as users, who need a
> > transparent way to calculate string length in bytes, irregardless of
> > loaded extensions or PHP version (no idea what PHP 6 / 5.3 would cause
> > in this case).
> >
> > So, is there any component of the framework where you would see a
> > static ::strByteLength($string) method? I was going to implement one in
> > Zend_Http_Client - but it's not really Zend_Http_Client specific.
> >
> > Suggestions welcome ;)
> >
> > Shahar.
> >
> >
signature.asc
Description: This is a digitally signed message part
