1

Closed

Easy way to execute PHP code from .NET

description

I haven't found an easy way to execute PHP code from a string, like for example in IronRuby or IronPython:
https://github.com/toburger/RulesEngine/blob/master/RulesEngine/Models/RubyRuleEngine.cs#L28
How can I realize such things via Phalanger?
 
I think such kind of usage for Phalanger would be of tremendous usefullness. Lots of people (also non-developers) know how to write PHP code and extending an application with PHP scripting capabilities would be great!
Closed May 19, 2012 at 8:55 AM by jakub

comments

jakub wrote May 2, 2012 at 1:49 PM

Phalanger has many ways of executing PHP code from .NET.
So it is possible to execute PHP code within one method call.

tobias wrote May 2, 2012 at 2:38 PM

Eval is exactly what I was looking for! Good Blog Post! Sorry, I must have missed this post.
Although I find the API a little clunky to use (internal stuff, the need to specify a dummy-.cs file)...

I've implemented the corresponding Phalanger rule like this:
https://github.com/toburger/RulesEngine/blob/master/RulesEngine/Models/PhpRuleEngine.cs
Let me know if I could implement it in a better way.

jakub wrote May 2, 2012 at 3:28 PM

yes, it was designed for internal use. There is actually no API, most of things are for internal runtime use. PhpRuleEngine looks great!

tobias wrote May 3, 2012 at 7:55 AM

I have a last question regarding the loading of PhpNetClassLibrary.dll (and other assemblies).
Is it okay to call context.ApplicationContext.AssemblyLoader.Load?

Example:
https://gist.github.com/2584105#L24

jakub wrote May 3, 2012 at 12:05 PM

context.ApplicationContext.AssemblyLoader.Load() is perfect.

tobias wrote May 19, 2012 at 3:03 PM

Please reopen the issue.

You said:
"yes, it was designed for internal use. There is actually no API, most of things are for internal runtime use."

It should exist an API to call PHP code from the CLR, like in other DLR languages. Look for example: http://blogs.msdn.com/b/seshadripv/archive/2008/07/28/various-ways-to-execute-script-using-the-dlr-hosting-api.aspx

phpEngine.Execute(code);
bool result = phpEngine.Execute<bool>(code);