Do not assume plus operators are available in other languages

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the dumb-mistakes-and-gotchas category.

Last Updated: 2024-11-21

I wrote the following code in PHP, assuming it would work based on my experience in various other languages that support adding strings "foo" + "bar" (i.e. the method String#+)

<? php

  url()->current() + "?foo=bar"

This gave the error: cannot add non-numeric

Lesson

In some programming environments conveniences like the plus symbol are not available on strings. i.e. It was naive of me to think this was a standard programming feature. Similarly, it is not a given that there will be Array#+ etc. Always check what operators are available.