downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

VARIANT> <COM
Last updated: Fri, 13 Nov 2009

view this page in

DOTNET

(PHP 4 >= 4.1.0, PHP 5)

DOTNETDOTNET クラス

$obj = new DOTNET("assembly", "classname")

説明

DOTNET クラスにより、.Net アセンブリからクラスを生成して そのメソッドをコールしたりプロパティにアクセスしたりできるようになります。

メソッド

string DOTNET::DOTNET ( string $assembly_name , string $class_name [, int $codepage ] )

DOTNET クラスのコンストラクタです。 読み込むアセンブリ名を assembly_name で指定し、アセンブリから生成するクラスを class_name で指定します。unicode 文字列の変換に使用するため、オプションの パラメータ codepage を設定することができます。 コードページの詳細については COM クラスを 参照ください。

返されるオブジェクトはオーバーロードされています。つまり、通常の クラスのような固定されたメソッドは存在しないということです。 そのかわりに、プロパティやメソッドへのアクセスは COM を通じて DOTNET に渡されます。言い換えれば、.Net ランタイムが提供する 機能によって .Net オブジェクトが COM 連携用にマップされているという ことです。

DOTNET オブジェクトが作成されると、PHP はそれを他の COM オブジェクトと同等のものとして扱い、同様の規則が適用されます。

例1 DOTNET の例

<?php
 $stack 
= new DOTNET("mscorlib""System.Collections.Stack");
 
$stack->Push(".Net");
 
$stack->Push("Hello ");
 echo 
$stack->Pop() . $stack->Pop();
?>

注意: この機能を使用するには、Web サーバに .Net ランタイムを インストールする必要があります。



VARIANT> <COM
Last updated: Fri, 13 Nov 2009
 
add a note add a note User Contributed Notes
DOTNET
m holmes at windowlogic dot com dot au
22-Sep-2009 04:31
For strongly-named NET assemblies that are registered in the GAC, you can just use the assembly name
e.g: $x = new DOTNET ("myAssembly", "myClass");

For strongly-named NET assemblies that aren't registered in the GAC, you need to use the full assembly string
e.g. $x = new DOTNET('myAssembly, Version=X.X.X.X, Culture=neutral, PublicKeyToken=ZZZZZZZZZZZZ', 'myClass');

You can't instantiate assemblies that haven't been strongly named.

"Strongly named" means that the assembly has a public key. To strongly name your own classes in Visual Studio, go to the Signing tab in the project properties and click the 'sign the assembly' box and choose a key file name.

To register an assembly in the GAC, there are various tools around to do that, but the easiest method is to drag-and-drop the compiled assembly into c:\windows\assembly using windows explorer (a shell extension is installed by default that handles registering dragged files).
kschroeder at mirageworks dot com
08-Apr-2009 06:55
In order to find out what the PublicKeyToken value is, open up Explorer and go to c:\windows\assembly.  In that directory you will see all of the registered assemblies along with their PublicKeyToken value.
Kai Sellgren
26-Mar-2009 05:14
My HTTPD crashed everytime I used this feature. To fix it, I had to switch to CGI and now everything works fine.
G dot B dot Yahav at Gmail dot com
05-Mar-2009 08:30
Here is a simple example using .NET Framework in PHP

<?php
$console
= new DOTNET("mscorlib", "System.Console");
$varible = $console->ReadLine();
$console->WriteLine( "Varible: " . $varible );
$console->WriteLine();

unset(
$varible );
unset(
$console );
exit();
?>
sam at bitopia dot co dot uk
02-May-2008 03:54
If you want to load any other assembly apart from mscorlib, you'll need to include it like the following

$x = new DOTNET('The.Assembly.Name, Version=X.X.X.X, Culture=neutral, PublicKeyToken=ZZZZZZZZZZZZ', 'The.Class.Name');

Replace all relevant details.

VARIANT> <COM
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites