In PHP, trim() exists.
By default the second parameter is " \n\r\t\v\x00"
I wish to introduce my own version which doesn't deviate far from the core functionality:
// Trim whitespace in addition to what the invoker requests
function trim_also( $string, $addl_characters = '' ){
return trim( $string, $addl_characters." \n\r\t\v\x00" );
}
Having recently expanded our Composer ecosystem, I wish to do something like:
namespace local;
class Override {
static function trim( $string, $addl_characters = '' ) {
return trim( $string, $addl_characters." \n\r\t\v\x00" );
}
// Assume ltrim() and rtrim() will exist
// Is it okay to have htmlentities() in here as well which sets defaults different than PHP?
}
This feels acceptable:
var_dump( \local\Override::trim( 'val1|val2|val3 | ', '|' ) );
// string(14) "val1|val2|val3"
What namespace/class naming and proximity scheme would you consider acceptable for such a function?
\local\Override::trim()\local\Strings::trim()\local\Helpers::trim()\local\MonkeyZeus::trim()\local\MonkeyZeus\Override::trim()\local\Util\Override::trim()\local\TrimStuff::trim()- considering my plans forhtmlentities(), I don't like this one
I feel the function is not specific to me nor any business logic nor niche use-cases and the other developers would gladly use it.
local\trim(...)? Do you really need a class? The namespace and Override class serve the same purpose in this case.<?php namespace local; function trim(){} ?>but then getting it to autoload involves additional hoops.