Don't call `strlen()` here. Use i.e.:
```php
for ($pos = 0, $length = strlen($scalar); $pos < $length; $pos++) {