Improve substr zend compatibility

Fixed issues with negative and out of bounds start position and length.