mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-06 23:48:50 +00:00
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:
@@ -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)) {
|
||||
|
||||
@@ -40,6 +40,7 @@ class Markup implements \Countable, \JsonSerializable
|
||||
return mb_strlen($this->content, $this->charset);
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->content;
|
||||
|
||||
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user