Surely a singleton class would be a nicer way to do this (or just leave the "tt_" off, why is it necessary, you're not overriding core functions)?
Surely a singleton class would be a nicer way to do this (or just leave the "tt_" off, why is it necessary, you're not overriding core functions)?
We decided against putting them in explicit namespaces, because we felt these were convenience functions and they should be convenient to use. We felt the convenience of:
if (tt_str_startswith($url, 'https://)) { }
over something like:
if (tt/global/string/starts_with($url, 'https://)) { }
was worth the lack of organization. We have <10 of these types of global functions in our code base and we are very careful about adding new ones. All other classes and functions are either in a namespace or class context.
We went with the tt_ prefix because we wanted to cover our bases and really explicitly ensure we never will collide with a PHP function, and we felt it isn't too unwieldy.
As for using a singleton class, since 5.3 we prefer to use namespaces instead.
use tt\global\string;
if (string\starts_with($url, 'https://)) { }However in this context again we felt that the convenience of just being able to throw these functions in place without having to worry about putting the proper use statement was worth the tradeoff.