Re: [PHP4BETA] no reverse fetch of arrays is BAD!

From: Date: Wed, 23 Feb 2000 06:58:22 +0000
Subject: Re: [PHP4BETA] no reverse fetch of arrays is BAD!
References: 1 2  Groups: php.version4 
Request: Send a blank email to php-version4+get-10696@lists.php.net to get a copy of this message
: > This is somewhat a feature request.... : > : > PHP should be able to: : > : > $x[] = 10; : > $x[] = 20; : > print $x[-1]; // 20, but PHP doesn't support this! : > : > But as I tested, it will accept negative index too! : > : > $x[-1] = 30; : > print $x[-1]; // 30, doesn't seem to affect any positive index : > : > Is that a feature? : : I think that negative indeces maybe a useful feature, because a few : languages have this : already (notably MUMPS AFAIK). And don't forget Perl! : The main difficulty for the such implementation in "C" or derived : languages is the method of calculating "effective address". IMHO the PHP I was thinking of getting the total count of the array and doing some very simple arithmetic calculation if the index < 0. probably: array [ total - (+INDEX) ] But, there is a major diff b/w perl and php: perl: $x[10] = "test"; // size of @x is 11 perl: $x[10] = "test"; // size of $x is 1 Which creates a new question: Is there a way to detect the upper bound of an array? : has not such limitations, because it has : got dynamically allocated cells in arrays (I can note big convergence : both PHP and MUMPS : in this issue). PHP is an interpreted language, and should make use full use of small (but cool and useful!) features this! Enjoy! Faisal

« previous php.version4 (#10696) next »