How to instantiate a .NET class in PHP that has a parameterized constructor?

I want to use the .NET class in PHP and use the PHP DOTNET class for this. I want to create an instance of a class with a parameterized constructor.

 $e = new DOTNET($full_assembly_string, $full_class_name); 

How to pass constructor arguments through this API?

+6
source share
1 answer

Impossible to do it

When performing this integration, you can solve several problems:

  • Public methods

As in the PHP manual, the returned object is an overloaded object that causes PHP to not know about the public methods that the object may contain. So, if you are var_dump, you will only see an empty array. This is why the internal structure of a DLL class must be known before it is called.

Fortunately for us, there is another tool specialized for this work that comes with the .NET platform called ildasm.exe. It is located next to gacutil.exe under c: \ Program Files (x86) \ Microsoft SDK \ Windows \ v7.0A \ Bin \ or c: \ Program Files (x86) \ Microsoft SDK \ Windows \ v6.0A \ bin. To load and display the DLL structure, simply call "ildasm.exe \ path \ to \ your.dll".

2. parameters Another problem is that you cannot pass parameters to the class constructor in the DLL.

  1. Data types

Being two different programming languages, we have different data types. In doing so, you will need to make sure that the methods of the DLL class return data types that PHP understands (mainly strings, ints, booleans, etc.). If your methods should return a list of arrays or a more complex structure, you can consider JSON for encoding.

More in

http://blog.zitec.com/2012/handling-net-assemblies-in-php/

0
source

Source: https://habr.com/ru/post/982248/


All Articles