On 17/01/2023 17:28, Craig Francis wrote:
I've seen this used a few times, e.g. starting with a numerical value (Passport 
number, NHS number, Social Security Number, Date of Birth 20230117), and the 
developer simply appends an incrementing letter on the end to get a unique 
reference; e.g. a person having multiple assessments... especially if it's more 
than 26 (A-Z), and you need to move to multiple letters, which `chr(90 + 1)` 
cannot help you with.

Being able to increment alpha strings is incredibly useful when working with Excel spreadsheets (as I do on a daily basis), because the column Ids match this pattern; and I would hate to see this deprecated. Having to replicate that logic for traversing column Ids in userland code would be inconvenient (to say the least), would affect many of the users of my libraries, and would have a performance impact on my libraries. If anything, I'd rather like to see the decrement operator work with alpha strings as well for more consistency.

I don't have the karma for a vote; but if I did then it would be a "No" for this alone, because I can see the problems that it will cause me and the users of my libraries.


That said, I appreciate that incrementing some strings can be a bit unusual (e.g. "A9" to "B0", vs 
"A 9" to "A 0").

Agreed. While incrementing works in a very logical manner with mixed alphanumeric strings, it's not well documented behaviour, and most developers take a long time before they understand what it's actually doing. While there might be use cases for incrementing alphanumerics, I suspect that it would be better implemented in the business logic of an application, because the component parts of that string are likely to have business meaning; and also to provide better code readability.


--
Mark Baker

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to