3 ms·
That was a design choice copied from perl. The perl design choice can be seen in https://perlmaven.com/what-are-string-and-numeric-contexts https://perlmaven.c
by shagie 2y ago
That was a design choice copied from perl.
The perl design choice can be seen in https://perlmaven.com/what-are-string-and-numeric-contexts https://perlmaven.com/what-are-string-and-numeric-contexts
https://perldoc.perl.org/perlop#Additive-Operators https://perldoc.perl.org/perlop#Additive-Operators
Though php doesn't have the numeric vs string contexts (it just is) which can change how perl behaves.
---
There is a bug in php with the lack of string vs numeric contexts can be seen in https://ideone.com/UntiCW https://ideone.com/UntiCW where the lack of a numericy vs stringy data difference creates an interesting bug when trying to replicate the magic of perl's ++ auto-increment on strings ( https://perldoc.perl.org/perlop#Auto-increment-and-Auto-decrement https://perldoc.perl.org/perlop#Auto-increment-and-Auto-decr... )
This doesn't exist in perl since "3d7" is a numericy value and "3d7"++ becomes "4". The "d9"++ becoming "e0" only works if it's a stringy value.
> The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern /^[a-zA-Z][0-9]\z/, the increment is done as a string, preserving each character within its range, with carry ...