[drupal-devel] What the difference between '==' and '==='
Hello, I was just doing some work, and work some reason the form_select would select every thing. Here is what I coded. form_select('', 'result][' .$payment->txnid, '', array('' => t('select result'), '1' => t('cleared'), '0' => t('dishonoured')) And for some reason every option was selected. I changed line 1329 in common.inc from ($value == $key ? ' selected="selected"' : '')) to ($value === $key ? ' selected="selected"' : '')) and it started working. Is my form_select call wrong, or is there some difference between == and === Thanks. -- Gordon Heydon <gordon@heydon.com.au>
The values on both sides of = = = have to be identical. There is no conversion by PHP as when using = =. $var = "123"; $var === 123; //false $var == 123; //true Carl McDade Gordon Heydon wrote:
Hello,
I was just doing some work, and work some reason the form_select would select every thing.
Here is what I coded.
form_select('', 'result][' .$payment->txnid, '', array('' => t('select result'), '1' => t('cleared'), '0' => t('dishonoured'))
And for some reason every option was selected.
I changed line 1329 in common.inc from ($value == $key ? ' selected="selected"' : '')) to ($value === $key ? ' selected="selected"' : '')) and it started working.
Is my form_select call wrong, or is there some difference between == and ===
Thanks.
Hello, Thanks for this, but I am not sure why everything was marked as selected. Gordon. On Wed, 2005-03-30 at 15:05 +0200, Carl McDade wrote:
The values on both sides of = = = have to be identical. There is no conversion by PHP as when using = =. $var = "123"; $var === 123; //false $var == 123; //true
Carl McDade
Gordon Heydon wrote:
Hello,
I was just doing some work, and work some reason the form_select would select every thing.
Here is what I coded.
form_select('', 'result][' .$payment->txnid, '', array('' => t('select result'), '1' => t('cleared'), '0' => t('dishonoured'))
And for some reason every option was selected.
I changed line 1329 in common.inc from ($value == $key ? ' selected="selected"' : '')) to ($value === $key ? ' selected="selected"' : '')) and it started working.
Is my form_select call wrong, or is there some difference between == and ===
Thanks.
!DSPAM:424aa545181922564531397!
-- Gordon Heydon <gordon@heydon.com.au>
Hmm, After I wrote that last post I realized that booleans may be effected also. You might check this: 0 == FALSE; //true 0 === FALSE; //false Carl McDade Gordon Heydon wrote:
Hello,
I was just doing some work, and work some reason the form_select would select every thing.
Here is what I coded.
form_select('', 'result][' .$payment->txnid, '', array('' => t('select result'), '1' => t('cleared'), '0' => t('dishonoured'))
And for some reason every option was selected.
I changed line 1329 in common.inc from ($value == $key ? ' selected="selected"' : '')) to ($value === $key ? ' selected="selected"' : '')) and it started working.
Is my form_select call wrong, or is there some difference between == and ===
Thanks.
On Wednesday 30 March 2005 08:11, Carl McDade wrote:
Hmm,
After I wrote that last post I realized that booleans may be effected also. You might check this:
0 == FALSE; //true 0 === FALSE; //false
Which is one of the main reasons for the existence of "===". Some functions, such as some of the string searches, can return zero as a real data value if they happen to match on the first character of a string, but they also return FALSE if they don't match at all. "===" provides the calling routine a way to distinguish between 0 and FALSE. It can also be used to distinguish, with some of the more complex data types such as strings, whether two reference variables are for the *same* item or for two *different* items that have the identical contents. Scott -- -----------------------+------------------------------------------------------ Scott Courtney | "I don't mind Microsoft making money. I mind them scott@4th.com | having a bad operating system." -- Linus Torvalds http://4th.com/ | ("The Rebel Code," NY Times, 21 February 1999) | PGP Public Key at http://4th.com/keys/scott.pubkey
participants (3)
-
Carl McDade -
Gordon Heydon -
Scott Courtney