For those of you who are hearing about Peachpie for the first time, the title of this article may seem even crazier than it does for the others. We are happy to announce that our project now allows you to compile PHP code directly for .NET Standard 2.0, which has a number of outrageous consequences.
Peachpie is a modern second-generation compiler and runtime for PHP code under the .NET and .NET Core frameworks. It runs entirely in safe managed code and its objective is to be fully compatible with regular PHP, while offering a variety of advantages thanks to the .NET platform, such as performance enhancements or bidirectional interoperability between C# and PHP.
Until now, the compilation with Peachpie ran on .NET Core 1.0 and we didn’t allow compiling without this version installed. The problem was that some features didn’t work because of this and several users struggled to set things up.
PHP on .NET Standard 2.0
Starting with Peachpie version
0.8.0-CI-460, you only have to have .NET Core 2.0 or newer installed and you can now compile PHP code to .NET Standard 2.0 and also reference any packages targeting up to
netstandard2.0. This means that Peachpie will produce a DLL file from legacy PHP source code, allowing you to port this code to the most modern platform in the .NET ecosystem. As a result, you can reference such a library for example from a .NET 4.7 project written in C#. Additionally, .NET Core 2.0 brings about a substantial performance increase, from which Peachpie-compiled PHP code can benefit significantly.
So what are the implications of all this? Why is .NET Standard 2.0 significant? First and foremost, Microsoft has increased the number of available APIs from about 13k in .NET Standard 1.6 to around 32k in 2.0. As Immo Landwerth states in the August announcement blog on .NET Standard 2.0, “these additions make it much easier to port existing code to .NET Standard, and, by extension, to any .NET implementation of .NET Standard, such as .NET Core 2.0 and the upcoming version of UWP.” This is, of course, also valid for PHP applications compiled with Peachpie.
As Peachpie makes PHP a first-class citizen in the .NET ecosystem, PHP apps can also benefit from the wide-ranging platform support .NET Standard offers. As of right now, the following platforms are currently supported:
- .NET Framework 4.6.1
- .NET Core 2.0
- Mono 5.4
- Xamarin.iOS 10.14
- Xamarin.Mac 3.8
- Xamarin.Android 7.5
- Upcoming version of UWP (expected to ship later this year)
For more information, tutorials on how to consume or create a .NET Standard library and much more, we definitely suggest referring to Immo’s blog post.