Bug #74100 [Com]: array_fill with negative $start_index works incorrectly

From: Date: Wed, 15 Feb 2017 09:42:33 +0000
Subject: Bug #74100 [Com]: array_fill with negative $start_index works incorrectly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207387@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74100&edit=1 ID: 74100 Comment by: andrew dot nester dot dev at gmail dot com Reported by: andrew dot nester dot dev at gmail dot com Summary: array_fill with negative $start_index works incorrectly Status: Open Type: Bug Package: Arrays related Operating System: Any PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Also I added PR with fix for this behaviour. Previous Comments: ------------------------------------------------------------------------ [2017-02-15 09:33:57] andrew dot nester dot dev at gmail dot com Description: ------------ When we are using array_fill function with negative $start_index it produces wrong array result. As I see this is documented behaviour (http://php.net/manual/en/function.array-fill.php#function.array-fill.example.basic ). Also there is note in documentation: "See also the Arrays section of manual for a detailed explanation of negative keys." But there is no any information about negative keys in arrays and why it should work like this. We can support negative indexes in arrays now that's why it's better to make array_fill work as expected. Test script: --------------- var_dump(array_fill_keys(range(-2,1), true)); var_dump(array_fill(-2, 4, true)) Expected result: ---------------- array(4) { [-2]=> bool(true) [-1]=> bool(true) [0]=> bool(true) [1]=> bool(true) } array(4) { [-2]=> bool(true) [-1]=> bool(true) [0]=> bool(true) [1]=> bool(true) } Actual result: -------------- array(4) { [-2]=> bool(true) [-1]=> bool(true) [0]=> bool(true) [1]=> bool(true) } array(4) { [-2]=> bool(true) [0]=> bool(true) [1]=> bool(true) [2]=> bool(true) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74100&edit=1

« previous php.bugs (#207387) next »