Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace Symfony\Polyfill\Php70; Chris@14: Chris@14: /** Chris@14: * @author Nicolas Grekas Chris@14: * Chris@14: * @internal Chris@14: */ Chris@14: final class Php70 Chris@14: { Chris@14: public static function intdiv($dividend, $divisor) Chris@14: { Chris@14: $dividend = self::intArg($dividend, __FUNCTION__, 1); Chris@14: $divisor = self::intArg($divisor, __FUNCTION__, 2); Chris@14: Chris@14: if (0 === $divisor) { Chris@14: throw new \DivisionByZeroError('Division by zero'); Chris@14: } Chris@14: if (-1 === $divisor && ~PHP_INT_MAX === $dividend) { Chris@14: throw new \ArithmeticError('Division of PHP_INT_MIN by -1 is not an integer'); Chris@14: } Chris@14: Chris@14: return ($dividend - ($dividend % $divisor)) / $divisor; Chris@14: } Chris@14: Chris@14: public static function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0) Chris@14: { Chris@14: $count = 0; Chris@14: $result = (string) $subject; Chris@14: if (0 === $limit = self::intArg($limit, __FUNCTION__, 3)) { Chris@14: return $result; Chris@14: } Chris@14: Chris@14: foreach ($patterns as $pattern => $callback) { Chris@14: $result = preg_replace_callback($pattern, $callback, $result, $limit, $c); Chris@14: $count += $c; Chris@14: } Chris@14: Chris@14: return $result; Chris@14: } Chris@14: Chris@14: public static function error_clear_last() Chris@14: { Chris@14: static $handler; Chris@14: if (!$handler) { Chris@17: $handler = function () { return false; }; Chris@14: } Chris@14: set_error_handler($handler); Chris@14: @trigger_error(''); Chris@14: restore_error_handler(); Chris@14: } Chris@14: Chris@16: private static function intArg($value, $caller, $pos) Chris@14: { Chris@16: if (\is_int($value)) { Chris@14: return $value; Chris@14: } Chris@16: if (!\is_numeric($value) || PHP_INT_MAX <= ($value += 0) || ~PHP_INT_MAX >= $value) { Chris@17: throw new \TypeError(sprintf('%s() expects parameter %d to be integer, %s given', $caller, $pos, \gettype($value))); Chris@14: } Chris@14: Chris@14: return (int) $value; Chris@14: } Chris@14: }