(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8)
The dotnet class allows you to instantiate a class from a .Net assembly and call its methods and access its properties, if the class and the methods and properties are » visible to COM.
Neither instantiating static classes nor calling static methods is supported.
Instantiating generic classes such as
is not supported either.
Some .Net classes do not implement IDispatch, so while they can be instantiated, calling methods or accessing properties on these classes is not supported.
You need to install the .Net runtime on your web server to take advantage of this feature.
Prior to PHP 8.0.0, .Net framework 4.0 and later were not supported by the dotnet class. If assemblies had been registered with regasm.exe, the classes could be instantiated as com objects, though. As of PHP 8.0.0, .Net framework 4.0 and later are supported via the php.ini directive com.dotnet_version.
The returned object is an overloaded object, which means that PHP does not see any fixed methods as it does with regular classes; instead, any property or method accesses are passed through to COM and from there to DOTNET. In other words, the .Net object is mapped through the COM interoperability layer provided by the .Net runtime.
Once you have created a dotnet object, PHP treats it identically to any other COM object; all the same rules apply.
Example #1 dotnet example
$stack = new dotnet("mscorlib", "System.Collections.Stack");
echo $stack->Pop() . $stack->Pop();