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


Groups > comp.lang.php > #15298

Re: problem with double as array index?

From "M. Strobel" <strobel@example.com>
Newsgroups comp.lang.php
Subject Re: problem with double as array index?
Date 2015-05-07 13:36 +0200
Organization A noiseless patient Spider
Message-ID <mifim4$oen$1@dont-email.me> (permalink)
References <midt9v$ihf$1@dont-email.me> <Nsv2x.180740$an3.113965@fx23.fr7> <mie5fl$l1l$1@dont-email.me> <mie6u1$7na$1@solani.org>

Show all headers | View raw


On 07.05.2015 01:08, Christoph M. Becker wrote:
> 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?

I am just trying to cheer up the PHP people. Stupid PHP bashing is below me.

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

You should start with defensive coding, by which I mean parameter checking, 
returncode checking. You can see in my first post that success of define is checked.

Then, of course, the tests.

/Str.

Back to comp.lang.php | Previous | NextPrevious 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