Phalanger and php library for .net

1.9k Views Asked by At

I have three php classes Im trying to use in my .net application. I used Phalanger to take those three classes and make a .dll file using this command:

phpc /target:dll Client.php Crypt.php Exception.php

Which of course outputted Client.dll as well as a Client.pdb files.

From there I went to VS2012 and created a new asp.net application and added the Client.dll as a reference. However I do not see the public methods from any of the classes and the object browser window shows:

Client>Client>Base Types>Object (so that I only have the methods of type Object)

I have tried this method/tutorial to get it to work which involves casting a custom interface onto your object however I get the error:

the type or namespace name ScriptContext could not be found

Which of course means that it doesnt know what or where ScriptContext. However this tutorial is from 2007 so I dont know if its just to far out of date or where I should get that class from?

The other tutorial I found is just as old. It says:

If you want to use existing PHP source (developed for standard interpreter) without modifications you have to use legacy mode, but when you want to develop new PHP project you can consider using pure mode

But I cannot find the step for legacy mode within the document and would prefer that over trying the "pure" mode (so that I dont have to change/edit my existing php code). I did try (pure mode) however it wouldn't compile (phalanger compile) with the command above (adding the DynamicObject.php class to the command).

How can I get to my public methods within the php class?

1

There are 1 best solutions below

5
On BEST ANSWER
phpc /target:dll Client.php Crypt.php Exception.php

creates DLL in legacy (standard) mode. This DLL contains 'weird' namespaces, needed for compatibility with PHP semantics. (these namespaces separate code from different script files). .NET interoperability overview of Phalanger 3.0 blog post describes how to use scripts compiled in standard mode.

Command line option /pure+ tells compiler to create so-called pure mode assembly. In this mode, compiler concatenates all the source files and compiles them as one (as C# does), without any weird namespaces. If you specify [\Export] attribute above the PHP class declaration, resulting DLL will look as it would be compiled from C# code, and you will be able to reference it and use its classes normally.