Merge branch '2.x' into 3.x

* 2.x:
  Add ReturnTypeWillChange to JsonSerializable implementation
  Fix implicit flot to int casts
This commit is contained in:
Fabien Potencier
2021-06-06 18:31:44 +02:00
3 changed files with 11 additions and 4 deletions
+2 -2
View File
@@ -346,7 +346,7 @@ function twig_cycle($values, $position)
function twig_random(Environment $env, $values = null, $max = null)
{
if (null === $values) {
return null === $max ? mt_rand() : mt_rand(0, $max);
return null === $max ? mt_rand() : mt_rand(0, (int) $max);
}
if (\is_int($values) || \is_float($values)) {
@@ -363,7 +363,7 @@ function twig_random(Environment $env, $values = null, $max = null)
$max = $max;
}
return mt_rand($min, $max);
return mt_rand((int) $min, (int) $max);
}
if (\is_string($values)) {
+1
View File
@@ -40,6 +40,7 @@ class Markup implements \Countable, \JsonSerializable
return mb_strlen($this->content, $this->charset);
}
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->content;
+8 -2
View File
@@ -167,9 +167,15 @@ class TemplateTest extends TestCase
$this->assertSame('Zero', $array[false]);
$this->assertSame('One', $array[true]);
$this->assertSame('One', $array[1.5]);
if (\PHP_VERSION_ID < 80100) {
// This line will trigger a deprecation warning on PHP 8.1.
$this->assertSame('One', $array[1.5]);
}
$this->assertSame('One', $array['1']);
$this->assertSame('MinusOne', $array[-1.5]);
if (\PHP_VERSION_ID < 80100) {
// This line will trigger a deprecation warning on PHP 8.1.
$this->assertSame('MinusOne', $array[-1.5]);
}
$this->assertSame('FloatButString', $array['1.5']);
$this->assertSame('IntegerButStringWithLeadingZeros', $array['01']);
$this->assertSame('EmptyString', $array[null]);