Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #15297

Re: problem with double as array index?

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: problem with double as array index?
Date 2015-05-07 01:08 +0200
Organization solani.org
Message-ID <mie6u1$7na$1@solani.org> (permalink)
References <midt9v$ihf$1@dont-email.me> <Nsv2x.180740$an3.113965@fx23.fr7> <mie5fl$l1l$1@dont-email.me>

Show all headers | View raw


M. Strobel wrote:

> On 06.05.2015 23:12, adam wrote:
>
>> Array key in PHP can either be an integer or a string. So when you use
>> 0.5 it
>> gets auto-casted to an int which gives 0, so:
>>
>> array (0=>1, 0.5=>2, 1=>3) would be equivalent to array (0=>1, 0=>2,
>> 1=>3)
>>
>> No magic here.
>>
>> http://php.net/manual/en/language.types.array.php
>
> Okay, got it, index can be an integer or a string, with automatic cast.
> 
> You have to be an extremely good programmer to circumvent traps like
> this, so kudos to all PHP programmers writing stable and correct programs.

Do I read some irony or even sarcasm here?

Anyhow, even for average PHP programmers like me, there are helpful
tools such as PHPUnit[1].  A simple unit test could check the expectations.

[1] <https://phpunit.de/>

-- 
Christoph M. Becker

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

problem with double as array index? "M. Strobel" <strobel@example.com> - 2015-05-06 22:25 +0200
  Re: problem with double as array index? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-06 22:57 +0200
  Re: problem with double as array index? adam <adam@nospam.net> - 2015-05-06 21:12 +0000
    Re: problem with double as array index? "M. Strobel" <strobel@example.com> - 2015-05-07 00:45 +0200
      Re: problem with double as array index? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-05-07 01:08 +0200
        Re: problem with double as array index? "M. Strobel" <strobel@example.com> - 2015-05-07 13:36 +0200

csiph-web