TSPHP introduces type casting for class-/interface types next to type casting for primitive types.
Please be aware, that object has a different meaning in TSPHP. The object cast:
\stdClass $a = (object) $b;
is not supported by TSPHP and results in a compiler error.
Following an example of an explicit cast:
Sub-types can be assigned to a parent-type without an explicit cast. In the example above this was done for
Please consider, that type juggling is not performed the same way as in PHP for scalar types. TSPHP adds some syntactic salt to its language definition compared to PHP. It is no longer possible to assign a scalar type to another one if data could get lost (e.g. assigning a string to int). One needs to use an explicit cast first (unless the cast modifier was used in the definition, then the explicit cast is turned into an implicit one).
Cast Assign Operator =()
TSPHP introduces a new operator: =()
This is a shortcut for cast the right side of the = to the type of the left side. Following some pair of examples, once with =() and once without.