3

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?

casperOne
  • 73,706
  • 19
  • 184
  • 253
owen gerig
  • 6,165
  • 6
  • 52
  • 91

1 Answers1

1
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.

Jakub Míšek
  • 1,036
  • 9
  • 12
  • If you have a phalanger project in visual studio, go to properties, and change Mode to Pure. – Jakub Míšek Oct 12 '12 at 15:40
  • Great link thanks! Part of my problem however is that I cannot find the class ScriptContext. The doc mentions that VS express edition isn't support, so is that why I do not see that class? – owen gerig Oct 12 '12 at 17:46
  • 1
    PHP.Core.ScriptContext is in PhpNetCore.dll ... VS Express has no support for 3rd party plugins - this means you cannot install Phalanger Tools plugin that utilize Phalanger/PHP projects and editor features, but it won't affect C# editor experience – Jakub Míšek Oct 14 '12 at 14:59
  • Thank you, I didnt realize that I had to browse to it at the "C:\Program Files\Phalanger 3.0\Bin" folder for that. – owen gerig Oct 15 '12 at 17:05
  • If you get a chance please check out my followup question (about the fact that phalanger isnt seeing my php classes)http://stackoverflow.com/questions/12901567/phalanger-cant-find-my-php-classes – owen gerig Oct 15 '12 at 18:20