Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!not-for-mail From: "M. Strobel" Newsgroups: comp.lang.php Subject: Re: loose thinking Date: Tue, 24 Jan 2012 14:32:52 +0100 Lines: 71 Message-ID: <9o7q84F33fU1@mid.uni-berlin.de> References: <9o7h5fFu6rU1@mid.uni-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de B4sNOc7lpl3RgAz7MYyTUgopClPzc2v0WtwN521y/aWj5Fap0= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.24) Gecko/20111101 Thunderbird/3.1.16 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.php:4594 Am 24.01.2012 14:04, schrieb "=C3=81lvaro G. Vicario": > El 24/01/2012 11:57, M. Strobel escribi=C3=B3/wrote: >> I hate this sloppiness of PHP: >> >> strobel@s114-intel:~> php -a >> Interactive shell >> >> php> $a[null] =3D 'you are Nothing'; >> php> var_dump($a); >> array(1) { >> [""]=3D> >> string(15) "you are Nothing" >> } >> php> $i=3Dnull; >> php> $a[$i] =3D 'you are Nothing'; >> php> var_dump($a); >> array(1) { >> [""]=3D> >> string(15) "you are Nothing" >> } >> php> var_dump(key($a)); >> string(0) "" >> >> There is no difference between an empty string and null in array index= ing. That is >> stupid. Why does the language not just respect my definitions? >=20 > Because your make your definitions fit in something that already have a= previous > definition. String keys must be integers or strings, as documented: >=20 > http://es.php.net/manual/en/language.types.array.php#language.types.arr= ay.syntax.array-func >=20 >=20 > It's the same situation where you pass a float to a function that's def= ined to expect > a string: your param will be cast to the target data type. >=20 > As about the array key definition, a key is an identifier so I think it= 's reasonable > to make it a string. >=20 > Having arrays where keys can be any arbitrary data type looks like an (= ahem) > interesting idea but you'll have to implement it yourself. If it can ac= tually be done > in pure PHP, the tool is possibly the ArrayIterator interface: >=20 > http://es.php.net/manual/en/class.arrayiterator.php >=20 >=20 >=20 Okay I see it is well documented. I just started testing. I am angry about it because not even isset() respects the null value here= =2E I think it makes more sense this way: isset($a[null]) should return false, because t= here is no null index. The point is that the designers of PHP (if you can talk about design here= ) probably meant to help programmers in not making all these hideous type distinctio= ns, but the outcome is you have to be really careful about loose comparison and unwa= nted type conversion, having to write even more if constructs. /Str.