Operators
Most of the PHP operators are present in THP.
Numbers
var number = 322
number + 1
number - 1
number * 1
number / 1
number % 2
number += 1
number -= 1
number *= 1
number /= 1
number %= 2
thp
There are no prefix/postfix increment operators (++
, --
),
use +=
or -=
instead.
// Use
number += 1
// instead of
number++ // This is a compile error
thp
Comparison
These operators will not do implicit type conversion. They can only be used with same datatypes.
v1 < v2
v1 <= v2
v1 > v2
v1 >= v2
thp
There is only ==
and !=
. They are equivalent to ===
and !==
.
v1 == v2
v1 != v2
thp
Bitwise
TBD
number and 1
number or 2
number xor 1
number xand 1
thp
Strings
Strings do not use .
for concatenation. They use ++
.
"Hello " ++ "world."
thp
This new operator implicitly converts types to string
"Hello " ++ 322 // 322 will be converted to "322"
thp
Boolean
These operators work only with booleans, they do not perform type coercion.
c1 && c2
c1 || c2
thp
Ternary
There is no ternary operator. See Conditionals for alternatives.
Null
These are detailed in their section: Nullable types
val person = some_fun()
person?.name
person?.name ?? "Jane"
person?.greet?.()
if person? {
person.name
}
thp