Argument #%d must be greater than or equal to 0

Description

This error is reported when a parameter is expected to be an integer, positive or zero. This is the case with the second argument of str_repeat().

Example

<?php
  str_repeat('abc', -1);

    // This is valid, and returns an empty string
  str_repeat('abc', 0);
?>

Literal Examples

  • str_repeat(): Argument #2 ($times) must be greater than or equal to 0

Solutions

  • Make sure the second argument is an integer, greater or equal to zero.

  • Use intval() on the value of the second integer.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.