Re: When is "z" != "z" ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2006/6/4, Rasmus Lerdorf <rasmus@xxxxxxxxxxx>:

Martin Alterisio wrote:

> Still:
> anything < ++anything
> should be true, or at least that's what they taught me on abstract data
> types design, and I think they're right (at least this time)

In loosely typed languages that is not always true.  Operators have to
guess at the type and try to do what the user expects.  There will
always be edge cases.  Being able to increment strings is pretty handy
when you need to create sequences for unique file and directory names.

For example, this also works:

$filename = "file1";
$filename++;
echo $filename;

You would get "file2" from this.  Think about the amount of code you
would need to write in C to make that work?

Then change $filename to "fileA" and increment it.  And you get "fileB".
  When we get to "fileZ" we don't want to go off into unprintable
character land, we want to try to stick with the pattern.

-Rasmus


I still don't see why this functionality should be a native operator of the
language.
It doesn't seem natural that ++ operator "understands" that the string could
be an enumeration of some kind. I believe that such things should be left to
the coder who knows what the string is really representing, not to the
language.

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux