Re: What am I doing wrong! Arrays



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Are you a PHP programmer by trade?

That a typical PHP behaviour, because PHP casts Strings to Ints before
comparing. This can be confusing. (Although they sell it as "good
usability") Ruby does not know implicit casts and thus 11 != "11".
Ruby is not as lax as PHP when it comes to types.

(Fun fact. Did you know that 11 == "11abcde"? Ask PHP. Second FF: Did
you know that a variable containing 0 or "0" is empty()?)

Regards,
Florian Gilcher

On Jun 30, 2008, at 10:27 AM, Sebastian Hungerecker wrote:

Tj Superfly wrote:
twelve = "12" and then changed it to array.length == twelve it does
the
same thing.

You're still compating array.length to "12", but Array#length returns
an integer, not a string. "12" is a string. array.length will return
12 and as Daniel said 12 == "12" is false. Whether you assign "12" to
a variable first or not.

HTH,
Sebastian
--
Jabber: sepp2k@xxxxxxxxxx
ICQ: 205544826


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkho32gACgkQJA/zY0IIRZYvewCeLtepLFf1XWzb9tQMsNFWozzR
g6oAoLGQhz4CyFJfmN1VWBRdeBlSZlFx
=zsUH
-----END PGP SIGNATURE-----

.



Relevant Pages

  • Re: Object of class Person could not be converted to string
    ... PHP has been lousy at maintaining backward compatibility. ... Objects are always converted to the string "Object". ... there's no reasonable gain in usability by forcing it ...
    (comp.lang.php)
  • HOW TO: eval() into a string
    ... evaluate a string with embedded php into a string.) ... PHP Functions as Wiki-isms ... embedded PHP functions that generate strings into a string of pure ... Then we can capture what is in the output buffer ...
    (alt.php)
  • Re: Object of class Person could not be converted to string
    ... PHP has been lousy at maintaining backward compatibility. ... They wouldn't have if the language had been better planned from the start. ... Objects are always converted to the string "Object". ...
    (comp.lang.php)
  • Re: Wordpress Port
    ... database stuff in PHP ... I'm passing a number in as a string. ... achieved the dubious distinction of being the first language I actually ...
    (comp.lang.ruby)
  • Re: Object of class Person could not be converted to string
    ... Objects are always converted to the string "Object". ... But it's not unusual for doc to lag the actual code changes, - in PHP or any other product. ... typed language any more. ...
    (comp.lang.php)