Foreach and Other Planned Work from PHP to .NET

Last week we introduced the recently implemented include functionality and benchmarked how Peachpie fares with it compared to standard PHP. This week we would like to present another newly included feature and to show what else we will be working on in the coming weeks.

Foreach

After include, static locals and fields, we have just finished including the support of foreach into Peachpie, which is a strong and very frequently used construct in PHP. It is most relevant during the compilation process. In the future it will work seamlessly with the .NET IEnumerable interface as well, which will allow for a close interoperability with .NET languages within any PHP code.

There is still a lot of room for future optimizations, but we are currently focused on making things work as quickly as possible. Most tweaks and improvements leading to an increased performance of Peachpie will be implemented subsequently.

Please refer to our GitHub page to see how the foreach construct was implemented into Peachpie. In short, the compiler processes variations of the following construct into MSIL.

*Notice that the snippet above underlines $arr and the tooltip explains that we have not yet defined this variable.

The resulting MSIL can be decompiled to its C# equivalent as

[csharp]
var enumerator = arr.GetForeachEnumerator(false, default(RuntimeTypeHandle));
while (enumerator.MoveNext()) {
value = enumerator.CurrentValue;
<context>.Echo(value);
}
[/csharp]

Future Work

While we are slowly checking off the tasks on our roadmap, let’s take a look at what is still on the agenda in order for Peachpie to be entirely compatible with PHP 7:

  • We need to transfer the library of standard PHP functions to the C# language. For this, we will heavily use the open-source code of the Phalanger project.
  • We need to ensure that Peachpie can run on a web server; for that we need to implement the request handler in order to launch Peachpie on IIS/Azure/Apache/Nginx and others.
  • There are several minor items, such as “list”, unset, destructors, indirect variables and class constants.
  • However, a few major operations still await us as well, like the support for PHP streams and the database layer.
  • Eval() and the seamless compilation of changed scripts while the compiled app is running.

The above points are all already part of our roadmap. We have already finalized their design and architecture, so their implementation should not represent too much trouble.

Posted on June 7, 2016, in category News, tags: , , , , , , ,