5 ms·
They're different operators. . is the string concatenation operator.
by VWWHFSfQ 2y ago
They're different operators. . is the string concatenation operator.
- wongarsu 2y agoAnd using a string concatenation operator that's distinct from the addition operator is one of PHP's best design choices. Naively everything passed to your script are strings, `"1"+1` evaluating to 11 instead of 2 would lead to so much wasted time.
- shagie 2y agoThat 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 ...