[TYPO3-core] RFC #10511: simplify and speed up t3lib_div::trimExplode()

Ingo Renner ingo at typo3.org
Sat Feb 21 15:01:52 CET 2009


uppsi :)
forget about v1!

v2 works now :)


Background info:

array_filter() is used to sort out empty values from the list/array. 
array_filter() uses trim() as a callback, passes it the current value 
and evaluates trim()'s return value as boolean.
Now it happens that sometimes in the core we pass strings to 
trimExplode() containing '0' (number zero as string) passing f.e. ' 0 ' 
to trim() results in '0' which evaluates to boolean false and is thus 
filtered out by array_filter()
We can't use empty() as callback either as it also evaluates '0' to 
boolean false.
The solution thus is to use a anonymous function as done in the patch, 
that reproduces the old behavior.

Best of all: It's still 30-50% faster!

Note:
with PHP 5.3 we can further streamline the code, I thus left a ToDo in 
the code.



all the best
Ingo

-- 
Ingo Renner
TYPO3 Core Developer, Release Manager TYPO3 4.2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: simpler_faster_trimExplode_v2.diff
Type: text/x-diff
Size: 5305 bytes
Desc: not available
Url : http://lists.netfielders.de/pipermail/typo3-team-core/attachments/20090221/51eb8ca1/attachment.diff 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.netfielders.de/pipermail/typo3-team-core/attachments/20090221/51eb8ca1/attachment.htm 


More information about the TYPO3-team-core mailing list