Bug #14310
closed
function uniqueList got list ended with commata
Added by Karsten Hachmeister about 20 years ago.
Updated over 18 years ago.
Description
If the function uniquiList in class.t3lib_div.php gets a list that ended with a commata a wrong SQL statement could be generated.
Added an if-statement, that checks, if the list ended with a commata, see added diff file.
(issue imported from #M350)
Files
Why not not just preg_replace it out? I admit it always runs, but the control structure to seach for this has to do the samething.
Just a thought,
Michael
function uniqueList() {
$listArray = array();
$arg_list = func_get_args();
foreach ($arg_list as $in_list) {
if (!is_array($in_list)) {
// MLC, remove ending ,
$in_list = preg_replace( '#,$#', '', $in_list );
$in_list = explode(',',$in_list);
}
$listArray = array_merge($listArray,$in_list);
}
return implode(',',array_unique($listArray));
}
If you think preg_replace is the better choice, ok. With regular expression I always think it is more cpu intensive?!
Well, both accomplish the same thing. I'd prefer to just run the command once, but as you said runtime should probably be the deciding factor. In the long run, I think whoever maintains this should make the decision.
Your substr method did help me solve something else though this morning. So thanks for the memory job on that function.
The time difference is not very much. I executed each variant 300000 times, the substr method took about 10,5 sek and the preg_replace method about 11,5 sek.
Also available in: Atom
PDF