New Version of Phalanger with Silverlight and VS 2008 Support
At the Lang.NET Symposium I presented several new features in Phalanger. I already posted the presentation and samples on the blog (here) and the talk is also available as a video on the Lang.NET web site (here - actually, due to the huge demand the site is down now, but I hope it gets back soon!) Anyway, the most interesting thing is that I've used Phalanger Integration for Visual Studio 2008 during the talk, which wasn't available in any Phalanger release until now.
I have to mention one more thing before talking more about the new release - Phalanger Integration for VS 2008 works with Visual Studio Shell, which means that you can get Visual Studio 2008 with Phalanger Support for free! Yes, that's right. Microsoft offers so called Visual Studio 2008 Shell, which is an "empty" IDE with no integrated languages and you can install Phalanger Integration into this version, which means that you can get very good Phalanger IDE (for Windows) for no cost at all!
If you can't wait to install this new version, you can skip the overview article and go directly to the installation links.
Phalanger at Lang.NET Symposium
Last week I attended the Lang.NET Symposium and I also did a short presentation about Phalanger (below you can find the demos and slides from my talk). By the way – during the trip from Prague to Seattle I missed a connecting flight from Paris, so I had one day to visit Paris and since I was traveling on Saturday I actually quite enjoyed it :-), so that’s where the picture comes from.
Overall it was really a fantastic event with many great talks from many interesting people. I hope that there will be recordings as a last year, so I won’t comment every topic that I found interesting (that would be really a long post). But just quickly – people from Microsoft often talked about DLR (dynamic language runtime) related topics, which was interesting as we’re planning to look at DLR in Phalanger. Luckily, Wez Furlong from the PHP community was there too, so we discussed how we could work on “PHP on DLR” project together (see also our mailing list).
There were also two talks about F# (from Luke Hoban and Harry Pierson), and it was a lot of fun to hang out with them. Finally, Erik Meijer presented the Volta project, which I was particularly interested in as it shares many goals and ideas with my F# Web Tools.
Non-Microsoft talks covered wider range of topics including Mono and Moonlight project (by Miguel de Icaza) and I actually had a chance to talk with Miguel about Phalanger and we even tried running the Helicopter sample on Moonlight – there were some issues, but it seems quite promising, so I hope to have the sample running on Moonlight on Linux quite soon! Miguel mentioned that the installation of Moonlight is currently a bit painful (due to some issues with media codecs), but it should be fixed in next few weeks, so I hope to be able to try it on my machine too!
Writing Silverlight applications in PHP
In my last post about Phalanger I mentioned that our important goal is to support the Silverlight (2.0) platform. Shortly Silverlight is a cross-browser platform that can be used for developing client-side components that run in the web browser and contain rich media, graphics and can interactively communicate with the user. The language that can be used for writing Silverlight code can be in general any .NET language, so our goal is to allow using PHP by making Phalanger compatible with Silverlight.
First steps were already made and it is becoming possible to write some very interesting things in Silverlight using PHP, there is of course still a lot of work to do and we're discussing the future development with PHP development team (you can join the mailing list PHP on DLR for more info). In this article we will first show a very basic Silverlight example that uses PHP and later I will shortly comment more complicated example - a game (quite addicting, so be careful :-)!) where you have to fly with helicopter and avoid the walls. The source code for helicopter game is also attached, so feel free to modify it or create similar games!
If you can't wait to try the demos before looking at the sources, here are the links:
- Simple car demo - Click on the car and it will move!
- Helicopter game demo - Click left button to fly up!
A few notes about Phalanger future
First, I'd like to aplogoize for the lack of new about the Phalanger project recently. I spent some time working as an intern with the F# team in MSR Cambridge and I also had final bachelor exam this autumn. Anyway, this doesn't mean that there isn't anything new and interesting regarding the Phalanger project comming soon - actually (as I believe) the opposite is true! The topics that I'm going to further discuss in this article is our upcomming support for Silverlight platform, the relation between Phalanger and DLR and also our desire to make Phalanger more open to the community, so stay tuned!
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.
Overload resolution in Phalanger
PHP language itself doesn't method support overloading (having two methods with same name, but different number or types of parameters). This brings an interesting problem to Phalanger, because most of .NET languages support this and if we want to be able to call any .NET object from PHP we need to add support (at least) for calling of overloaded methods. The latest Phalanger release contains overload resolution described in the Integrating PHP with CLR document .
For example, when calling the
Console::WriteLine method (which has a lot of overloads), Phalanger dynamically generates
a piece of code that we call dynamic stub, which is responsible for choosing the most appropriate overload depending on the actual
parameter types. This stub is generated only once for every method, which makes this implementation very efficient. The difficult part of
overload resolution is, how can the stub determine what is the best overload? PHP language has a lot of implicit conversions, so
when you pass the string
"10.2 Little Piggies" to a method it can be implicitly converted to float (
(For more details see ). Another example of implicit conversion is that any boolean value can be
converted to string (empty string or string
"0" are converted to
false, every other string is converted
In this article I'll describe how does the dynamic stub look like in current version of Phalanger, what problems can it cause and how are we going to fix it in the future version!
Compiling Texy! with Phalanger
Texy!  is a convertor from text format (similar to formats used in some wiki applications) to valid XHTML code written in PHP. The syntax is described at Texy! web page . Unfortunately, it is only in Czech language, but the syntax is very straightforward, so you can understand it without learning Czech :-).
In this article, we'll examine how to compile Texy! using Phalanger in pure mode. In this mode it is possible to use objects from PHP like any other .NET objects, so we can later used the compiled assembly for example in the following C# code:
// Create instance of Texy! parser Texy t = new Texy(); // Call the 'process' method and cast result to string string parsed = (string)t.process(txtTexy.Text); // Display parsed text using literal ltrOutput.Text = parsed;
Phalanger has a new website!
As you may know, I became new project lead for the Phalanger project [^]. Phalanger was started as a project at Charles University (where I'm studying) by Tomas Matousek, Ladislav Prosek and 4 other guys, the first version was very successful and they started wokring on the second version which introduces PHP in the family of first-class .NET languages (which makes it fully interoperable with the rest of .NET world). After releasing the second version, Tomas and Ladislav moved to Microsoft and convinced me to continue in the Phalanger development. Most of the work on the 2.0 version was already done, so we're currently working on implementing the rest of the PHP/CLR language extensions, making Phalanger more compatible with existing PHP apps and so on. For more information about the history of Phalanger visit the project history page [^].
I think that Phalanger is in the phase when it can be very interesting for both PHP and .NET communities, but it never got greater publicity and there are not very much examples and articles to demonstrate the interesting Phalanger features. To improve this we started working on the new Phalanger website where users could share their experiences, tips etc. We used PHP wiki called DokuWiki [^] (running, of course on Phalanger) and you can find the new website here:
- Phalanger - Homepage [^] (the new project homepage)
- Phalanger - User wiki [^] (you can edit pages in user wiki after logging in)
I also wrote two articles about Phalanger (and I'm working on more :-)) to explain the most important and interesting Phalanger features and concepts. You can find the articles at our web:
- Phalanger for .NET developers [^] - focused on .NET interoperability and features interesting for C# developers
- Phalanger for Mono users [^] - Phalanger 2.0 supports Mono, so here is an introduction for Mono users
I'll also continue blogging about Phalanger, so you can expect more information about Phalanger, problems that we're currently solving as well as some other tips, tricks in this blog. If you're interested only in Phalanger you can use this RSS feed to monitor new articles in this blog (it shows only articles with the Phalanger tag).