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


Groups > comp.lang.php > #15297

Re: problem with double as array index?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.php
Subject Re: problem with double as array index?
Date Thu, 07 May 2015 01:08:56 +0200
Organization solani.org
Lines 29
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>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1430953729 7914 eJwFwQkBwDAIA0BLpYRPTmDFv4Tdmbr4BNwctrbv4Lw7GsJdpXVcejnmyyFi6yEywWYlW+wHIy8RZw== (6 May 2015 23:08:49 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Wed, 6 May 2015 23:08:49 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
X-User-ID eJwFwYEBwCAIA7CXYNBOzlEL/59ggqDz/kkwMZgqxFBm2rEBrE5fPGXqgKd9JyUw1LwS8QANoxDV
In-Reply-To <mie5fl$l1l$1@dont-email.me>
Cancel-Lock sha1:EdyUM232xVI8BZId38LxN42gesw=
X-NNTP-Posting-Host eJwNwokRwCAMA7CV8tpkHCDN/iNQndKhuAwkIifH1HQv+0Sqaed/BaebzqMeoKB6KacSStkPBIEQCQ==
Xref csiph.com comp.lang.php:15297

Show key headers only | 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