forum > PHP and lastIndexOf

  • Hi all,
    I think the PHP implementation of the String.lastIndexOf function is not consistent with the rest of technologies. The PHP is as follows

    function _hx_last_index_of($s, $value, $startIndex = null) {
        $x = strrpos($s, $value, $startIndex === null ? null : strlen($s) - $startIndex);
        if($x === false)
            return -1;
        else
            return $x;
    }

    So the startIndex parameter refers the end of the string while it should refer the begining of the string as other implementations. The 3rd argument of the php function strrpos wants the position to start counting, from the start of the string. Hence the operation

    strlen($s) - $startIndex

    is not adequate and it should be simply:
    $x = strrpos($s, $value, $startIndex);

    Is it actually a bug or I'm missing something? By the way, congrats for this so useful platform I'm just starting to use.

  • Thank you for the report, it has been fixed on SVN: http://code.google.com/p/haxe/source/detail?r=5211

    Simon

< Prev | Page 1 / 1 | Next >