[wp-hackers] PHP Coding Practices

Mark Jaquith mark.wordpress at txfx.net
Thu Feb 16 01:11:20 GMT 2006

On Feb 15, 2006, at 5:07 PM, Robert Deaton wrote:

> Your tests are not near detailed or run enough times to be a true
> indication. Here's something I threw together that might be a more
> accurate test, that tries not only real time, but cpu time as well,
> because both are very important to us, we need to keep server load
> down.

You're right, my tests were simplistic.

Replacing the existing strstr() instances with strpos() would have to  
be done manually... or with several regexes (that might mess things  
up).  But what would be easy is to replace all instances of "strstr("  
with "wp_strstr(".  We could then make something like:

function wp_strstr($haystack, $needle) {
	if ( strpos($haystack, $needle) !== false )
		return true;
	return false;

Would passing it through a function like that erode too much of the  
benefit that strpos() offers?  I like this approach, because strpos 
($haystack, $needle) !== false is ugly... and is prone to error (if  
someone accidentally uses !=, or just checks boolean true/false).   
wp_strstr($haystack, $needle) is much  easier to read and to code.   
And I easily made that change project wide with a simple search/replace.

Can you run your test between strstr() and wp_strstr() and see if it  
is still worth doing?
Mark Jaquith

More information about the wp-hackers mailing list