webmozarts / assert

Assertions to validate method input/output with nice error messages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

String length determined by visual width, not character count

njandreasson opened this issue · comments

I was looking at the possibility of using this library in a project but stumbled upon the following in the source code: https://github.com/webmozart/assert/blob/4a8bf11547e139e77b651365113fc12850c43d9a/src/Assert.php#L937

My intention was to use the lengthBetween() method which in turn uses the static strlen() method.

I'm curious why mb_strwidth() is used which returns the visual width instead of mb_strlen() which returns the character count?

For example, if you want to set a limit on a method to make sure only a certain amount of characters are passed in so it will fit into a database column it would make more sense to use mb_strlen().

Or is there a particular reason for this choice that I'm missing?
I compared to beberlei/assert which is another potential library I'm considering and it uses mb_strlen()

Thanks for what otherwise looks like an excellent library!