Yeah, this is very silly thing using arrays without quotes,

I once had this problem - learned it - and sticked to using quotes whenever
is not an integrer.


advising to everyone,

 Maxim Maletsky
 Founder, Chief Developer

 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com




-----Original Message-----
From: Simon Garner [mailto:[EMAIL PROTECTED]]
Sent: Friday, February 23, 2001 1:32 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Counter Help


From: "Chris Lee" <[EMAIL PROTECTED]>

> change
>
> $row[count]
>
> to
>
> $row['count']
>
> it thinks the work [count] is some kind of conastant, it doesnt know you
> mean (string) 'count'
>


<rant>

I have noticed a lot of people do not put quotes on their array indexes
(e.g. VBulletin is a prime offender) - imho this is a really bad practice
because your code becomes ambiguous.

Example:

<?php
    define("foo", "donkey");

    $test = array("foo"=>"orange", "bar"=>"purple");

    echo $test[foo];
?>

Now, I think that should print nothing (or an error), because there is no
index matching "donkey" (the value of the constant "foo"). But for some
reason PHP looks for an array index matching the string "foo" as well,
encouraging this kind of sloppy programming.


Regards

Simon Garner


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to