Re: Variable name declarations?
| From: | teo at gecadsoftware dot com | Date: | Sun, 15 Jul 2001 14:56:08 +0000 |
| Subject: | Re: Variable name declarations? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-57940@lists.php.net to get a copy of this message | ||
Hi Kent!
On Sat, 14 Jul 2001, Kent Sandvik wrote:
>
> > function sum_array( $input_array )
> > {
> > var $index;
> > var $sum = 0;
> >
> > for( $index = 0; $index < count( $input_array ); $index++ )
> > $sum += $input_array[ $index ];
> >
> > return $sum;
> > }
>
> The array variable issue has indeed bitten me a couple of times, so now all
> my arrays are called $<something>_arr. It would nice to introduce more
> runtime checking of array types and complaints in case non-array values are
> used in functions. But otherwise the strong type checking will just cause
> more problems and more overhead with calls. I don't know if the example
> above will help that much, but you could already write similar code in
> functions to make sure that the values are declared on top, to make things
> clearer.
>
you can add:
!is_array($input_array) && ($input_array = array($input_array);
before your for() loop, if the "client" of sum_array() doesn't guarentee to
provide only arrays.
-- teodor