After some work around the usage of Peachpie, we got back to implementing core functionalities in the compiler itself.
We are edging closer towards completing the project in its initial form and being able to run full real-world applications.
Peachpie is a compiler and runtime of PHP on top of .NET. As a complete re-implementation of the PHP language, it allows extensions being written in pure .NET and enables PHP to run on the .NET Framework, as well as .NET Core and Mono. Peachpie can seamlessly utilize .NET objects and, on the other hand, lets C# code directly access compiled PHP functions, variables and classes.
The ambition of the Peachpie project is to allow for a migration of PHP codebases to .NET and thereby to enable using the best of both worlds, providing the .NET and ASP.NET runtimes to PHP through their respective APIs.
Microsoft Build 2017
In other news, Jakub and Ben from the Peachpie core development team will be present at this year’s Microsoft Build conference in Seattle. If you plan on being around and would like to meet with us, feel free to drop us an email and we’ll be happy to set something up.
What’s new in Peachpie 0.7.0?
We are happy to announce the new and updated version of Peachpie, as well as the corresponding VSCode extensions. Lots of things have changed since 0.6.0, so let’s take a look at some of the principal additions in more detail. Keep in mind that Peachpie is still not in version 1.0, so full applications are unlikely to run out of the box and we do not generally recommend running Peachpie in a production setting.
In the Peachpie platform, PHP sessions are somewhat of a layer over the ASP.NET Core or ASP.NET sessions, which have a whole host of different configuration options. As a result, Peachpie allows PHP to have high throughput sessions using e.g. the ASP.NET Core distributed cache (IDistrubutedCache) seamlessly. Any sessions server configuration you set on ASP.NET Core instance, Peachpie will directly use for the implementation of
session_start and other functions. The point of this is that the original PHP codebase uses the legacy PHP API without any changes and will thus benefit from the implementation in the modern ASP.NET Core.
As mentioned in an earlier article,
create_function() are already available in Peachpie. We would like to reiterate that we do not recommend using these functions as they are often the sign of bad programming practices. However, what’s interesting about them is that they use the so-called scripting API internally, which allows us to run PHP scripts directly from a C# environment in runtime.
Peachpie is becoming a more and more mature platform, which is continuously being tested on our servers; through the compilation and analysis, it also offers a variety of diagnostics. Recently, we have also started testing the compiler itself, ensuring that it returns the correct diagnostics (warnings and errors in the compiled code) and we will gradually expand the scale of analyzed constructs. An advantage for the user is that a majority of cases where the compiler crashed on purpose now returns a meaningful error message with a description that helps the developer understand the situation.
Hover over the variable
$p in line 3 to see the error message.
Experimental implementation of generators
Since version 0.6.1, you could already experiment with PHP generators, which is the equivalent of enumerators in C#. As we are still in the experimental stages of this implementation, we will not discuss this in more detail in this article. If you are interested in this particular topic, feel free to browse the PHP documentation. For now, Peachpie doesn’t support
yield as an expression, but in the form of a statement, the construct works perfectly.
With the new version, we have also published an update to our Visual Studio Code extension, which you can get from the Marketplace. The version reflects the most recent changes and allows you to work with Peachpie in the fast lightweight IDE efficiently.
Experimental support for image and GD2
We have also added an initial experimental support for graphical functions. When you reference the
Peachpie.Library.Graphics package, you gain a basic support for graphical functions. However, this is still under development, so if you would like to speed this up, we welcome any developments as long as they meet our coding standards.
Other newly supported constructs
The above changes are not the only updates to the Peachpie compiler platform. Since 0.6.0, Peachpie also received support for mail, coalesce operator, ambiguous types (will be discussed in greater detail in a future article), various SPL iterators, PDO, MSSQL, anonymous classes or closures. Additionally, we have made hundreds of different fixes to the compiler.
If you want to experiment, check out our Console Application sample, which is already updated to the new version.