What’s New in PeachPie 0.9.43

There are plenty of new features, improved interoperability between PHP and C#, compatibility enhancements and tons of fixes in the latest release of PeachPie compiler.

There have been a lot of new improvements to PeachPie since the last blog post discussing a new release, so we decided to sum up what’s new since version 0.9.38. Some of the new additions and improvements make for very interesting topics.
We divided these changes into several groups, e.g. fixes, compatibility enhancements with regular PHP, and of course unique features that only make sense on .NET.

New and improved features

  • $(PhpRelativePath) – this new MSBuild property allows you to set your compiled code into a virtual subfolder. This means that if you’re compiling file.php and you set <PhpRelativePath>subpath</PhpRelativePath> , after the compilation the file will behave as if it were in subpath/file.php. Read more: https://docs.peachpie.io/php/msbuild/#phprelativepath.
  • [ObsoleteAttribute] – compiled methods are annotated with this well-known attribute whenever there is the @deprecated PHPDoc tag. As a result, both the PHP and C# compilers will give you a warning when you use a deprecated PHP function.

For example, the following PHP code gets compiled into a binary DLL assembly file and the corresponding XML documentation file.

 * Renders the screen's help.
 * @since 2.7.0
 * @deprecated 3.3.0 Use WP_Screen::render_screen_meta()
 * @see WP_Screen::render_screen_meta()
function screen_meta( $screen ) {

The result is equivalent to the following C# code. Notice the PHPDoc comment gets stored into an XML comment and the @deprecated comment is emitted as metadata.

/// <summary>
/// Renders the screen's help.
/// </summary>
[Obsolete("3.3.0 Use WP_Screen::render_screen_meta()", false)]
public static void screen_meta(Context <ctx>, PhpValue screen)
  • Argless constructors – previously, compiled PHP classes required an additional “magic” parameter Context. Now, however, you can use compiled PHP classes in C# absolutely seamlessly without anything special. Context is still needed but it is managed internally for the current .NET ExecutionContext.

The implications of this are far-reaching and some of it should and will be discussed as a separate blog post. In general, however, this is a massive interoperability improvement, and it opens up many new use cases for the PHP ecosystem.

Compiler fixes and enhancements

The compiler suffered from some nullref exceptions and incorrectly emitted IL. Thanks to all your issues, here are some of the recent fixes of some issues that were found:

  • negative condition ILif (!X) was emitted unnecessarily as
    .load X, .conv.i, .ldc.i4.0, .ceq, .brtrue, changed to something shorter and more equivalent to what the C# compiler does:
    .load X, .conv.i, .brfalse
  • traits – when compiled and then referenced from a DLL, the compiler did not get it and crashed.
  • overload resolution – the compiler was picking the wrong method when there were more overloads.
  • correct .call/.callvirt OP code – this fixes running PHP on .NET Core 3.0 as described on https://www.peachpie.io/2019/05/php-on-net-core-3-0.html


Of course all our contributors are also helping with the implementation of the standard PHP library. This includes new PHP functions and classes implemented in C# and improving the compatibility of compiled PHP apps. The following list is just a subset of new standard PHP functions that are now available to compiled PHP programs:

  • fixes to iterators and RecursiveDirectoryIterator
  • improved reflection classes
  • DateTime improvements
  • PCRE support with more PCRE syntax
  • cURL support for proxy and more options
  • T_ constants
  • updated MySqlConnector library
  • SessionUpdateTimestampHandlerInterface
  • php_user_filter
  • other PHP functions

Share this article:Share on FacebookShare on VKPin on PinterestShare on Google+Tweet about this on TwitterShare on LinkedInShare on Reddit
Posted on June 25, 2019, in category Information, News, tags: , , , , , , ,