Why php has two different operators for addition? -


i've came c# , found annoying php operators . , + reason have 2 different operators same purpose, addition?

so if there reason why php has these two, why c# doesn't?

sorry, kind dumb question, me looks redundant , annoying.

php has 'dynamic' or 'type not known until runtime' variables. i.e. interpreter and/or programmer cannot know until run time type of information in variable. now, let assume have 2 variables , both contain character strings can interpreted numbers.

i.e. $foo = "2014" , $bar = "0301";

now assume + plus sign has work out want do?

do want these treated numbers , added together? giving 2315.

or 'sortable' date field of "20140301' i.e. yyyymmdd?

there no way '+' operator know , correct thing in circumstances.

hence need 'concatenation' operator '.'.

the '+' operator converts numbers , adds.

the '.' operator converts string , concatenates.

we need both.

in language 'typed' variables can work out context i.e. types of variables, programmer intended.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -