priority
Standard
status
New Issue

qcodo
0.4.14 (Stable)
category
QForm / QControls (PHP)
php
Any



Votes
There are no votes for this issue.
Example Code

print strlen('aĆ©');
Expected Output
2
Actual Output
3

reported: monday, october 4, 2010, 3:50 am pdt  |  by: Gaspar Attila  |  messages: 4 messages  |  last: about 3 years ago


#1  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Monday, October 4, 2010, 3:50 AM PDT

When I use UTF-8 as QApplication::$EncodingType in QTextBoxBase Validate function character counting return a bad value because strlen is not a multibyte safe function.

My solution:
Changing strlen to mb_strlen and adding QApplication::$EncodingType as second parameter.

#2  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Monday, October 4, 2010, 10:11 AM PDT

Yeah -- the problem is, however, that mb_string (and actually the entire mb_ extension) isn't a “standard” extension for PHP.

I think you're solution does make sense -- I just think we should put it around a “if function_exists()” wrapper so that we don't break BC.

Actually, this probably is a larger task, in general.  Obviously the framework uses a lot of string-based methods (strpos, strlen, etc.) which assumes an 8-bit character set.  Even though Qcodo is trying to push for UTF-8 by default... the result is that we get slightly quirky behavior when we introduce any multibyte characters.

Originally I was going to defer to the PHP folks, especially with all the push for PHP 6 and native UTF-8 support.  However, since PHP 6 has essentially been shelved indefinitely, I think it does make sense to revisit having a clean, standard approach for multibyte/internationalized characters for Qcodo.

I do like continuing to have UTF-8 by default for Qcodo.  But I think what might make the most sense, throughout the entire framework, is to utilize the MB_ extension for installations that are truly working with multibyte characters, and for those that aren't working with multibyte characters and that do not have the mb_ extension installed, it will still fall back gracefully and work (as long as you aren't working with multibyte characters).

That basically means that we will be having if function_exist() wrappers around any/ALL calls to strlen, strpos, str_replace, etc., calling the mb_ version if that function exists, and otherwise calling the standard PHP version of those functions if it doesn't.

I'd be happy to hear folks' thoughts.

#3  |  Fernando Lordán (Barcelona, CAT, Spain) Spain
Thursday, September 29, 2011, 9:33 AM PDT

The easiest solution could be to encapsulate all the potentially problematic string functions inside a new QString class, where string manipulation could be wrapped easily in only one place to avoid having checks all over the application code. Of course all the application (starting with Qcodo) should use that functions instead of the PHP native ones.

It's nothing more than an elegant patch, until more robust internationalization support comes from PHP itself. But it's the same idea of having a QDateTime class for managing that specific type.

#4  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Thursday, September 29, 2011, 10:00 AM PDT

Actually, it's a lot like how we do QApplication::HtmlEntities() since we're not really talking about using QString as a class to store each string value, we're merely talking about implementing a lot of QString methods as static methods to do things like strlen, etc.

I think it makes sense -- the only thing I'd want to do is make sure we're not going to take a big performance hit on this.  Calls to things like the native strlen() are incredibly fast... and the framework (and pretty much all PHP apps) call string manipulation methods very often.  If there's even a small perf hit, it can go a long way in greatly degrading the performance of a qcodo app, which is definitely something we do not want to do.



Copyright © 2005 - 2014, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.