6 ms·
> Python does not do implicit type conversion except in arithmetic. You can't do, e.g., `4 + "hello"` Interestingly, PHP uses separate operators for numerical
by chriswarbo 5y ago
> Python does not do implicit type conversion except in arithmetic. You can't do, e.g., `4 + "hello"`
Interestingly, PHP uses separate operators for numerical addition (+) and string concatenation (.), so it's actually a bit more explicit than e.g. Javascript (where 'x + y' could result in normal numerical addition, or normal string concatenation, or implicit conversion to a numerical addition, or implicit conversion to a string concatenation!)
- throw_m239339 5y ago> Interestingly, PHP uses separate operators for numerical addition (+) and string concatenation (.), so it's actually a bit more explicit than e.g. Javascript (where 'x + y' could result in normal numerical addition, or normal string concatenation, or implicit conversion to a numerical addition, or implicit conversion to a string concatenation!) Only because Rasmus didn't know how to design and implement a "proper" programming language. This isn't a intended feature, it just made parsing easier for him.
- onaworkcomputer 5y agoRasmus borrowed this distinction from Larry Wall, since PHP was originally implemented in Perl (which also uses + for addition and . for string concatenation). The neat thing about PHP and the + operator is that you can sometimes trick the interpreter into doing math on the underlying bytes of the string: http://dominic-mulligan.co.uk/wp-content/uploads/2015/05/SREPLSApr2016.pdf http://dominic-mulligan.co.uk/wp-content/uploads/2015/05/SRE...
- TazeTSchnitzel 5y agoThere's nothing improper about having a separate operator for concatenation.
- throw_m239339 5y ago> There's nothing improper about having a separate operator for concatenation. Only to monopolize that operator to then have to use "->" for method call. C/C++ do that because of dereferencing. There is no need for that in PHP OO, all objects are passed by pointer to functions or methods.
- giaour 5y agoMeh, other languages manage to assign multiple meanings to single tokens and depend on context to resolve ambiguity. PHP's issue here is that it refuses to do so, which is how we ended up with the backslash as a namespace delimiter.