Re:PHP Commandments
by kijin on Tuesday April 30, 2013 @12:12PM
(#5633050)
I have a similar dilemma with some of my helper functions. For example, I have starts_with(), ends_with(), and contains() for super easy string comparisons, is_between() for numerical comparisons, and custom implementations for a few built-in functions such as hex2bin() that don't exist in older versions. These are so general in scope that it would be awkward to place them in their own \Namespace\Class.
[ Parent
| on HN ]
I'd probably break them all down into classes based on function (EasyString, EasyNumber, BuiltIn).
namespace App\Library;
class EasyString {
public static function starts_with();
...
}
and then just use them like this: use App\Library\EasyString as ES;
along with an autoloader.