backport PHP bugfix #43540

Summary: We need to properly set newlength.

See:
- https://github.com/php/php-src/commit/898ff10dc0f799ecf997cb3c64a96f2751884187
- https://bugs.php.net/bug.php?id=43540
Closes https://github.com/facebook/hhvm/pull/4014

Reviewed By: @ptarjan

Differential Revision: D1626102

Pulled By: @fredemmott