PHP Deprecated: Ds\Vector::slice(): Passing null to parameter #2 ($length) of type ?int is deprecated in /test.php on line 7
PHP Stack trace:
PHP 1. {main}() /test.php:0
PHP 2. Ds\Vector->slice($index = 2, $length = NULL) /test.php:7
Deprecated: Ds\Vector::slice(): Passing null to parameter #2 ($length) of type ?int is deprecated in /test.php on line 7
Call Stack:
0.0001 402344 1. {main}() /test.php:0
0.0001 402608 2. Ds\Vector->slice($index = 2, $length = NULL) /test.php:7
/test.php:7:
class Ds\Vector#2 (0) {
}
This is inconsistent with how array_slice(), and by extension the polyfill work, which treat null the same as when no argument is passed: https://3v4l.org/rqsnF . It also makes using a variable harder, eg:
@HypeMC this is great, thank you. Feels like we could simplify the parsing a bit, but this looks great. I'm looking forward to coming back to this project a bit, it's been too long.
Currently the
slice()
methods don't work if the value of$length
isnull
, eg:This is inconsistent with how
array_slice()
, and by extension the polyfill work, which treatnull
the same as when no argument is passed: https://3v4l.org/rqsnF . It also makes using a variable harder, eg:This PR proposes allowing passing
null
as the length and treating it the same as when the argument isn't passed.Tests: https://github.com/php-ds/tests/pull/23