Using PHP objects from C# in a type-safe way
When you want to call PHP scripts from mainstream .NET languages, like C# you can follow two different ways. First you can use the pure mode as I demonstrated in one of the earlier articles on PHP application called Texy!. This approach can be used only for some specific applications, because pure mode has several restrictions - the two most important restrictions are that no global code or inclusions are allowed (you have to specify all source files during the compilation), but thanks to this restrictions Phalanger is able to produce classes that are compatible with .NET and can be called from C#. Second option is to create object dynamically by its name and perform all method invocations by name too. This approach can be used with any PHP scripts, but it isn't very convenient. In this article we present new features in the Phalanger beta 4 which extend the second approach and make it possible to use objects from any PHP script in C# using type-safe way.
Published: Monday, 30 April 2007, 1:26 AM
Read the complete article
Phalanger 2.0 Beta 4 available!
This week we finished new release of Phalanger (the PHP compiler for .NET platform). The goal in this release was to fix many minor bugs preventing us from running some of the famous and most often deployed open-source PHP applications, so with the new release you'll be able to run for example MediaWiki, the wiki application that evolved from system used on Wikipedia or probably the best-known PHP blogging and publishing system WordPress. Other applications that we tested can be found at Phalanger website in the list of tested PHP applications [^]. Compatibility is very important for us, so if you have troubles running any open-source PHP application, let us know and we'll include it in our list!
Another thing that we focused on is interoperability between PHP scripts compiled using Phalanger
and other .NET languages. Using .NET objects from Phalanger is very intuitive and has almost no
limitations, however the other way is a bit difficult because of the dynamic nature of PHP language.
If your PHP application can be compiled in the Phalanger pure mode, than the
PHP objects can be exported and made available to C# and other languages. The methods of objects
exported using this method take
object (the base class for every .NET object) as
a parameter, because PHP checks types at runtime, so this may be a bit confusing for the users.
In the Beta 4 we tried to target these two issues - first, the fact that you have to use pure mode
and second, the fact that exported objects can't contain any information about accepted types.
This is a topic for entire article, so I'll write about it soon... Stay tuned :-)!
Here are the links for Phalanger 2.0 Beta 4 release:
- Phalanger 2.0 Beta 4 release page [^] - CodePlex
- Phalanger MySQL extension Beta 4 [^] - CodePlex
Published: Sunday, 22 April 2007, 4:24 PM
Read the complete article