Computer Science has a notion of “type safety”. In a given language, there are different “types” of things. Any operation you can do also specifies what types it’s allowed to act on. “1 + 1” is allowed, but “1 + hello” isn’t.
The following code is a perfectly legitimate expression in most languages:
1 + hello
In this case, 1 is a numeric literal and hello is a symbol which, if it happens to be the name of a variable in the current scope, could certainly be added to 1 (assuming the types are compatible).
Now, perhaps you meant to write this instead:
1 + "hello"
Here we are adding a numeric literal to a string literal, which indeed does not work, in many languages. (But not all! If you doubt this, open your browser’s JavaScript console right now, type 1 + "hello", and hit Enter.)
Forgot that code blocks existed. I typed “1 + hello” because when I went to put quotes around ‘hello’ I saw I was already using them to designate a chunk of code, and went “eh, maybe people will guess hello is a string”. You know, because if I know it’s a string, everyone must know it’s a string, right?
I think it might hold in PHP. At least the random REPL that I found evaluates echo hello to hello in standard output (with a warning, though it did execute).
Nitpick:
The following code is a perfectly legitimate expression in most languages:
In this case,
1
is a numeric literal andhello
is a symbol which, if it happens to be the name of a variable in the current scope, could certainly be added to 1 (assuming the types are compatible).Now, perhaps you meant to write this instead:
Here we are adding a numeric literal to a string literal, which indeed does not work, in many languages. (But not all! If you doubt this, open your browser’s JavaScript console right now, type
1 + "hello"
, and hit Enter.)Forgot that code blocks existed. I typed “1 + hello” because when I went to put quotes around ‘hello’ I saw I was already using them to designate a chunk of code, and went “eh, maybe people will guess hello is a string”. You know, because if I know it’s a string, everyone must know it’s a string, right?
Heh, indeed.
For future reference (for other people reading this, even if you know), you do inline code styling with backticks, like so:
becomes:
This single
word
will be styled like inline code.And for code blocks:
becomes:
(EDIT: Corrected formatting.)
In what languages does the OP’s claim hold?
I have no idea.
I think it might hold in PHP. At least the random REPL that I found evaluates
echo hello
tohello
in standard output (with a warning, though it did execute).Indeed not:
As you see,
hello
is interpreted as"hello"
—but as a consequence,1 + hello
is perfectly legitimate (and evaluates to1
… because PHP is weird).Ah, of course. Obviously PHP isn’t type-safe in any way. It does throw a warning at least in the REPL I tried.