Fix boundary cases of strspn, strcspn and substr_replace

Summary: I'm all for refactoring, but a precondition for refactoring is that the original copies of the code in some way resemble each other. While the bounds checks for strspn, substr_replace and substr might look superficially similar, in fact they can't be merged with a single simple if(strict) to take care of the divergence. The main problem is that multi-pass normalization of the inputs gives you some interesting and arguably broken behaviour when there are multiple issues that need to be simultaneously fixed.

So, unrefactor (expand?) string_substr_check() into its three consistutent parts, with code in the two new parts based closely on the Zend source in the current git master. Remove the "strict" parameter, now implicitly true.

Added a test case which previously failed in multiple ways. In particular, strspn('','x') returned the wrong thing, which broke the MediaWiki parser quite badly. The expect file was generated by PHP 5.5 and is identical to the one generated by PHP 5.3.

Closes #2987

Reviewed By: @ptarjan

Differential Revision: D1393755

Pulled By: @fredemmott
Add MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH logic to store_result

Summary: This is the same as #3016 but moves the implementation to PHP instead.

It actually does not fix the bug itself because PHP behaves the same.
The cause of the segfault is that some people run out of memory resulting in a bad call to calloc.
calloc returns a nullptr which later in mysql is dereferenced.

PHP's solution to this is to call store_result before binding. But this will also fail in hhvm.
This fixes it.

Thanks SiebelsTim for writing the original diff in C++

TL;DR: TEXT in mysql is now variable length instead of 4GB when calling store_result

Fixes #2377
Fixes #2921

Reviewed By: @JoelMarcey

Differential Revision: D1407344