Import statement
From PhalangerWiki
import statement was introduced in Phalanger/2.0 to allow interoperability with .NET, ASP.NET code behind and WinForms designer. This was designed when PHP6 was not fully specified, and Phalanger needed to use .NET namespaces.
Since Phalanger/3.0, use statement was introduced and import statement has been deprecated.
[edit]
Usage
import namespace A\B\C; import namespace D\E\F;
Import statements have to be the very first statements in the source code. Specified namespaces are imported into the naming context of the current source file. All type names are then tried in concatenation with specified namespaces (as it is in C#).
[edit]
Phalanger 3.0
Since Phalanger/3.0, import statement is deprecated. However if it is used, it slightly changes semantics of standard PHP aliasing:
- When an import statement is used, not fully qualified names within a namespace are not prepended with the namespace name. Instead of that, specified imports are prepended before the name to find an existing class.
- Import statement is allowed only in pure mode.
[edit]
Example
<?
import namespace System\Collections; // this imports naming context into current source code
// import namespace System:::Collections; // in Phalanger 2.0 - 2.1
class Program
{
static function Main()
{
$x = new Hashtable; // instantiate \System\Collections\Hashtable
}
}
?>
