On 19 July 2013 12:34, Yasuo Ohgaki <yohg...@ohgaki.net> wrote: > Hi, > > 2013/7/19 Peter Lind <peter.e.l...@gmail.com> > >> On 19 July 2013 11:18, Dan Cryer <d...@dancryer.com> wrote: >> >>> What's the intended use case for string increment / decrement? >>> >>> >> Personally, I instantly think of mirroring spreadsheet columns - works >> quite well in that context. >> > > ++/-- 'XYZ00001234' would have use cases. > > >> >> >>> It just seems like madness to me, using mathematical operators with >>> strings, producing seemingly arbitrary results in some circumstances (C -> >>> B -> A -> NULL / False ?). >>> >>> >> Throw a warning and don't decrement A/a any further - that's not >> arbitrary. >> > > -- is more problematic. > --'XYZ0000' would be 'XYZ0000' or 'XYY00000' or 'XYY'? > > php -r '$a = "YZ9"; var_dump(++$a);' gives me ZA0
If php -r '$a = "ZA0"; var_dump(--$a);' doesn't give YZ9 you'll just be left scratching your head. Granted, you might be left scratching your head as to why string incrementing works at all, but that can of worms was opened long ago. It would be better not to change length of string, IMO. > e.g. --'XYZ0000' became 'XYY0000' > > I'd go with --XYZ0000 -> XYY9999 Also, the string length shouldn't factor into it. > All chars would stop decrement at lowest chars of [0-9], [a-z], [A-Z]. > e.g. Lowest value of 'XYZ0000' is 'AAA0000'. > > This is not a symmetric operation of ++, but it's impossible to achieve > symmetric > operation ++/-- on strings anyway. > > Only at the edge case - and I personally can't see why that would mean asymmetric operation in the rest of the cases. -- <hype> WWW: plphp.dk / plind.dk CV: careers.stackoverflow.com/peterlind LinkedIn: plind Twitter: kafe15 </hype>