tchwork / utf8

Portable and performant UTF-8, Unicode and Grapheme Clusters for PHP
Apache License 2.0
627 stars 50 forks source link

Function Overloading #15

Closed CMCDragonkai closed 10 years ago

CMCDragonkai commented 10 years ago

I read on the Readme that:

This library is orthogonal to mbstring.func_overload and will not work if the php.ini setting is enabled.

This library does not overload the standard string functions right? I also read on some posts on StackOverflow that overloading the string functions may have bad consequences when using third party libraries that use the string functions for binary operations and hence expect the normal string functions. http://evertpot.com/mbstring-function-overloading-dont-use-it/

If that's the case, let's assume I'm building a library that is intended to be used with other projects that will do some string manipulation. It's purpose is not string manipulation and hence I don't want to force an extension like mb_string.

How should I go about using functions like strlen()? Should I test for if the function mb_strlen() exists, and use it, or if it doesn't exist, use the basic strlen()?

nicolas-grekas commented 10 years ago

You're right, this lib doesn't override any PHP function. What this article says is true, mbstring overloading is a nightmare. You have several possibilities to work around if you want to make your own code work under such condition: