Re: Re: PHP 4.0 Bug #5226 Updated: arrayfields reorganized when using array_pop

From: Date: Mon, 03 Jul 2000 16:05:46 +0000
Subject: Re: Re: PHP 4.0 Bug #5226 Updated: arrayfields reorganized when using array_pop
References: 1 2 3  Groups: php.dev 
Request: Send a blank email to php-dev+get-23334@lists.php.net to get a copy of this message
On Tue, Jun 27, 2000 at 09:01:04AM -0500, Andrei Zmievski wrote: > On Tue, 27 Jun 2000, Stanislav Malyshev wrote: > > Then array_pop($input) and array_splice($input, -1) would do different > > things. Don't know if anybody cares... Numeric keys in PHP are weird. > > You're right. So maybe it's best that we don't care about the keys. I > have no idea why someone would start keys from 1 or 5. If we don't care about keys (you probably don't do that when you use push and pop anyway), it makes sense to do it the fastest way. The fastest is to delete just the one element. I would suggest that push/pop and shift/unshift just removes the element preserving keys/indices while splice doesn't. Or to make it clear, keep splice but change the stack/queue functions. If you want a general solution, what about having an additional internal splice function that just deletes elements rather than putting all the ones to be preserved on a new hash. You could use that for push/pop and shift/unshift, and possibly array_splice could have an additional argument for saying whether you want keys/indices to be preserved or rearranged. I wish an index 1 and a key "1" would be treated differently. I don't think it's too hard implement this, but I'm afraid such a change would break too much code. Maybe for PHP5??? Stig

« previous php.dev (#23334) next »