Re: PHP Unicode extension in PHP6
| From: | Tomas Kuliavas | Date: | Sat, 19 May 2007 15:48:07 +0000 |
| Subject: | Re: PHP Unicode extension in PHP6 | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-29564@lists.php.net to get a copy of this message | ||
>> SquirrelMail scripts are designed to work with binary strings. They will
>> have to deal with emails written in many different character sets. In
>> some
>> cases scripts must know string length in bytes and not in symbols. If
>> PHP
>> starts converting email body or message parts, strings won't match
>> information stored in email headers.
>
> Try this, you'll see it's really easy:
> <?php
> //in Unicode mode all strings created this way are Unicode strings
> $s = "<any unicode string>";
> var_dump(strlen(($s)));
> var_dump(strlen((binary)$s));
> ?>
http://www.php.net/language.types.type-juggling#language.types.typecasting
No (binary).
PHP 4.1.2 = parse error in test2.php on line 5.
PHP 5.2.0 = Parse error: syntax error, unexpected T_VARIABLE in test2.php
on line 5
It is E_PARSE error, so I can't apply fix after detecting PHP6.
Fix is not portable. We are talking about SquirrelMail code. Minimal PHP
4.1.x requirement.
Good fix is closer to
<?php
//in Unicode mode all strings created this way are Unicode strings
$s = "<any unicode string>";
var_dump(strlen($s));
// add php6 test here {
settype($s,'binary');
// }
var_dump(strlen($s));
?>
I will have to write wrappers for all affected functions. Not wise.
strlen("\xC4\x85") = 2. strlen((binary)"\xC4\x85") = 4. Not good. It is
one character in utf-8.
Nevermind. Will watch how PHP6-dev changes and wait for better documentation.
--
Tomas