You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
2.0 KiB

  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Polyfill\Php70;
  11. /**
  12. * @author Nicolas Grekas <p@tchwork.com>
  13. *
  14. * @internal
  15. */
  16. final class Php70
  17. {
  18. public static function intdiv($dividend, $divisor)
  19. {
  20. $dividend = self::intArg($dividend, __FUNCTION__, 1);
  21. $divisor = self::intArg($divisor, __FUNCTION__, 2);
  22. if (0 === $divisor) {
  23. throw new \DivisionByZeroError('Division by zero');
  24. }
  25. if (-1 === $divisor && ~PHP_INT_MAX === $dividend) {
  26. throw new \ArithmeticError('Division of PHP_INT_MIN by -1 is not an integer');
  27. }
  28. return ($dividend - ($dividend % $divisor)) / $divisor;
  29. }
  30. public static function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0)
  31. {
  32. $count = 0;
  33. $result = (string) $subject;
  34. if (0 === $limit = self::intArg($limit, __FUNCTION__, 3)) {
  35. return $result;
  36. }
  37. foreach ($patterns as $pattern => $callback) {
  38. $result = preg_replace_callback($pattern, $callback, $result, $limit, $c);
  39. $count += $c;
  40. }
  41. return $result;
  42. }
  43. public static function error_clear_last()
  44. {
  45. static $handler;
  46. if (!$handler) {
  47. $handler = function () { return false; };
  48. }
  49. set_error_handler($handler);
  50. @trigger_error('');
  51. restore_error_handler();
  52. }
  53. private static function intArg($value, $caller, $pos)
  54. {
  55. if (\is_int($value)) {
  56. return $value;
  57. }
  58. if (!\is_numeric($value) || PHP_INT_MAX <= ($value += 0) || ~PHP_INT_MAX >= $value) {
  59. throw new \TypeError(sprintf('%s() expects parameter %d to be integer, %s given', $caller, $pos, \gettype($value)));
  60. }
  61. return (int) $value;
  62. }
  63. }