FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » loose thinking
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: loose thinking [message #176782 is a reply to message #176781] Tue, 24 January 2012 13:04 Go to previous messageGo to previous message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma:
Senior Member
El 24/01/2012 11:57, M. Strobel escribió/wrote:
> I hate this sloppiness of PHP:
>
> strobel@s114-intel:~> php -a
> Interactive shell
>
> php> $a[null] = 'you are Nothing';
> php> var_dump($a);
> array(1) {
> [""]=>
> string(15) "you are Nothing"
> }
> php> $i=null;
> php> $a[$i] = 'you are Nothing';
> php> var_dump($a);
> array(1) {
> [""]=>
> string(15) "you are Nothing"
> }
> php> var_dump(key($a));
> string(0) ""
>
> There is no difference between an empty string and null in array indexing. That is
> stupid. Why does the language not just respect my definitions?

Because your make your definitions fit in something that already have a
previous definition. String keys must be integers or strings, as documented:

http://es.php.net/manual/en/language.types.array.php#language.types.array.s yntax.array-func

It's the same situation where you pass a float to a function that's
defined to expect a string: your param will be cast to the target data type.

As about the array key definition, a key is an identifier so I think
it's reasonable to make it a string.

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 actually be done in pure PHP, the tool is possibly the ArrayIterator
interface:

http://es.php.net/manual/en/class.arrayiterator.php



--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Open Source Customization
Next Topic: Product page getting Redirect back to Home page - Please Fix
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 03:54:21 GMT 2024

Total time taken to generate the page: 0.05437 seconds