[wp-hackers] PHP Coding Practices

Mark Jaquith mark.wordpress at txfx.net
Wed Feb 15 12:30:03 GMT 2006


On Feb 14, 2006, at 7:19 PM, Mark Jaquith wrote:

> WP currently uses strstr() in many places just to establish basic  
> "this string exists in that string" functionality.  According to  
> http://php.net/strstr, "Note:  If you only want to determine if a  
> particular needle  occurs within haystack, use the faster and less  
> memory intensive function strpos() instead."

You know what?  I just ran a bunch of speed tests.  I used small  
haystacks and big haystacks.  I ran strstr($haystack, $needle)  
against strpos($haystack, $needle) !== false (as well as the opposite  
versions with a million iterations each.  strstr() is faster by  
anywhere from 5 to 20%.  Plus, it looks nicer in the code.

So now this is just about casting to array for foreach() rather than  
testing with !empty().  Any objections?
--
Mark Jaquith
http://txfx.net/




More information about the wp-hackers mailing list