Skip to end of metadata
Go to start of metadata

The changes due to type safety are not listed in the following changes. Those changes cover statements which are not related to type safety (at least not directly) but will not be supported by TSPHP.

Multiple default cases in switch statements

It is perfectly legal to define more than one default case statement for a switch statement in PHP (this might well change in the future, see reported bug https://bugs.php.net/bug.php?id=67757 and the corresponding RFC https://wiki.php.net/rfc/switch.default.multiple). Probably you are thinking now "whaaat? and which default case is used? the first, the last, all of them?". Do not worry about it, TSPHP does not support this "feature" since it hampers the readability of the code pretty much. If you are still curious which default statement is executed then have a look at the following PHP code.

PHP code
Icon
Please be aware, that TSPHP can not detect normal double cases because one can use an expression as a case label. TSPHP does not guarantee that always the first case is selected even thought it seems like PHP 5.4 behaves like this.

Use statement outside of a namespace

It is valid to write a use statement outside of a namespace in PHP even though the statement has no effect.

The following example causes a compiler error.

Would cause a compiler error

Pseudo optional parameters

It is valid to define an optional parameter followed by a non-optional parameter in PHP. Have a look at the following example:

PHP code

It is not possible to call the function foo without defining a value for $b and therefore $a is a pseudo optional parameter. TSPHP does not support this construct and thus optional parameters have always to be at the end of the parameter list.

Have a look at the following valid and reasonable statement in PHP (thanks to Johannes Schlüter for the hint).

PHP code

This construct is not valid in TSPHP. One can use the ? operator to specify that the parameter can be null. Please have a look at Function parameters  for more information.

Using a name of a keyword as identifier

PHP allows the use of the name of some keywords as identifiers (somehow they are not treated as keywords). Have a look at those (confusing) examples, which are all valid in PHP.

PHP Code

One would probably never write something like this. In TSPHP it is just not possible.

Type aliases

TSPHP does not support the type aliases boolean, integer, double and real. They can not be used as type for a variable, type of a return value etc. nor in a cast. The following examples would all cause a compiler error.

Would cause a compiler error

Case sensitive class/method/function names

In contrast to PHP, class names as well as method and function names are case insensitive in terms of declaration. That means, it is not allowed to define two (or more) functions with the same name in a case insensitive manner. Thus the following would cause a compiler error:

Would cause a compiler error

However, if one wants to call the functoin, then he has to use the case sensitive name. Thus the following would cause a compiler error as well:

Would cause a compiler error

The same applies for class and method names. It is not allowed to have two (or more) classes with the same name in a case insensitive manner per namespace and a class itself cannot contain two or more methods with the same name in a case insensitive manner.

We could say, the names are case sensitive but to protect the names, in order to avoid ambiguous names such as foo and Foo, the names are case insensitive during the definition check of the compiler.

 

 

  • No labels