locutusjs / locutus

Bringing stdlibs of other programming languages to JavaScript for educational purposes

Home Page:https://locutus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with PHP substr() and empty strings

djmattyg007 opened this issue · comments

Description

PHP's implementation of substr() returns an empty string under the following conditions, not false:

substr("", 0);
substr("", 0, 0);

Locutus's implementation of substr() returns false for these arguments.

Actually it looks like PHP's implementation of substr() returns an empty string if the first two arguments are "", and 0, regardless of what the third argument is.

Further investigation: it will return false if the third argument is less than zero. It will only return an empty string if the third argument is greater than or equal to zero.

I'll work on this, unless you (@djmattyg007) are interested in preparing a pull request?
I will check the PHP function's source code.

I don't have time sorry. Feel free to go ahead yourself.

I've pushed a tiny patch that fixes just the reported scenario, but there are more nuances in PHP that potentially need to be covered, which I'll do in separate patches.