Re: foreach() for strings

From: Date: Wed, 22 Jun 2011 13:40:22 +0000
Subject: Re: foreach() for strings
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  Groups: php.internals 
Request: Send a blank email to internals+get-53509@lists.php.net to get a copy of this message
Am 22.06.2011 15:30, schrieb Gustavo Lopes: > Em Wed, 22 Jun 2011 13:21:10 +0100, Reindl Harald <h.reindl@thelounge.net> escreveu: > >> Am 22.06.2011 14:14, schrieb Gustavo Lopes: >>> It's actually 3 lines: >>> >>> function str_is_utf8($str) { >>> return $str == "" || htmlspecialchars($str, 0, "UTF-8"); >>> } >> >> >> WTF should this do? >> this won't return boolean >> > > The reason it works is that > 1) || coerces the operands into booleans (if they get to be evaluated) > 2) htmlspecialchars returns "" on bad input sequence > 3) (bool) "" === false > > But even if you didn't know these things, you should have bothered to at least test it > before sending this response and why this will not return true if $str is ISO-8859-1?

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#53509) next »