php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41836 array_pad does not fill last element when using negative pad and empty source
Submitted: 2007-06-28 08:13 UTC Modified: 2007-06-28 08:54 UTC
From: lubbers_corrado at yahoo dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.3 OS: Windows XP SP2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: lubbers_corrado at yahoo dot com
New email:
PHP Version: OS:

 

 [2007-06-28 08:13 UTC] lubbers_corrado at yahoo dot com
Description:
------------
When trying to fill an _empty_ array by using array_pad with negative direction, the last element will be padded but stays empty

When the source Array has at least one element, this error does not occur

Reproduce code:
---------------
$foo = array();
$foo = array_pad($foo,-2,"bar");
echo print_r($foo,true);


Expected result:
----------------
Array ( [0] => bar [1] => bar );

Actual result:
--------------
Array ( [0] => bar [1] => );

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-28 08:28 UTC] tony2001@php.net
Cannot reproduce.
 [2007-06-28 08:38 UTC] lubbers_corrado at yahoo dot com
i also cannot reproduce again...strange happenings on my system i assume .
 [2007-06-28 08:41 UTC] lubbers_corrado at yahoo dot com
Ok, i can reproduce again. it only happens when generating an array by splitting an empty string. Check the example again, please

$foo = explode('*',"");
$foo = array_pad($foo,-2,"bar");
echo print_r($foo,true);
 [2007-06-28 08:49 UTC] lubbers_corrado at yahoo dot com
changed category to "arrays related"
 [2007-06-28 08:50 UTC] tony2001@php.net
array_pad() does not change already existing values and your array contains empty string.
 [2007-06-28 08:54 UTC] lubbers_corrado at yahoo dot com
ok, thats it. Logical mistake by myself. Thank you for the fast reply!
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Mon Sep 14 01:00:01 2026 UTC