[thelist] PHP question... checking string length

Andrew Clover and-evolt at doxdesk.com
Mon Mar 28 04:52:40 CST 2005


Matt Warden <mwarden at gmail.com> wrote:

> Java strings are not mutable.

Ahem. Yes. Dunno why I said mutable there, when I really just meant an 
object with identity. tsk.

(It is indeed unusual for an immutable value type one can write as a 
literal to have identity, which is why Java Strings trip people up.)

Anyway, I just ran an ad hoc test to see whether the speed issue 
persists in PHP and the result is: no, precisely the opposite in fact. 
The test strlen($a)==0 seems to be consistently 50%-60% slower than 
$a=='' in PHP in at least the very limited script I tested. [under PHP 
4.3.1, IIS 5.1]

So I'd advise against using this 'optimisation' under PHP.

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/


More information about the thelist mailing list